{"id":111444,"date":"2025-08-07T07:00:00","date_gmt":"2025-08-07T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111444"},"modified":"2025-08-07T10:35:00","modified_gmt":"2025-08-07T17:35:00","slug":"20250807-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250807-00\/?p=111444","title":{"rendered":"How can I detect that Windows is running in S-Mode?"},"content":{"rendered":"<p>Windows S-Mode is a mode of Windows which restricts programs to those which came from the Microsoft Store. You might have a program that is available from the Microsoft Store (therefore is allowed to run in S-Mode), and you want to know whether to suggest that the user install a companion program that is not allowed in S-Mode. How can a program detect whether the system is running in S-Mode?<\/p>\n<p>You can detect S-Mode by using the <code>Windows.<wbr \/>System.<wbr \/>Profile.<wbr \/>Windows\u00adIntegrity\u00adPolicy<\/code> class.<\/p>\n<pre>\/\/ C#\r\nusing Windows.System.Profile;\r\n\r\nif (WindowsIntegrityPolicy.IsEnabled) {\r\n    \/\/ System is in S-Mode\r\n    if (WindowsIntegrityPolicy.CanDisable) {\r\n        \/\/ System is in S-Mode but can be taken out of S-Mode\r\n        suggestCompanion = true;\r\n    } else {\r\n        \/\/ System is locked into S-Mode\r\n        suggestCompanion = false;\r\n    }\r\n} else {\r\n    \/\/ System is not in S-Mode\r\n    suggestCompanion = true;\r\n}\r\n<\/pre>\n<pre>\/\/ C++\/WinRT\r\n#include &lt;winrt\/Windows.System.Profile.h&gt;\r\n\r\nnamespace winrt\r\n{\r\n    using namespace winrt::Windows::System::Profile;\r\n}\r\n\r\nif (winrt::WindowsIntegrityPolicy::IsEnabled()) {\r\n    \/\/ System is in S-Mode\r\n    if (winrt::WindowsIntegrityPolicy::CanDisable()) {\r\n        \/\/ System is in S-Mode but can be taken out of S-Mode\r\n        suggestCompanion = true;\r\n    } else {\r\n        \/\/ System is locked into S-Mode\r\n        suggestCompanion = false;\r\n    }\r\n} else {\r\n    \/\/ System is not in S-Mode\r\n    suggestCompanion = true;\r\n}\r\n<\/pre>\n<pre>\/\/ JavaScript\r\nlet WindowsIntegrityPolicy = Windows.System.Profile.WindowsIntegrityPolicy;\r\n\r\nif (WindowsIntegrityPolicy.isEnabled) {\r\n    \/\/ System is in S-Mode\r\n    if (WindowsIntegrityPolicy.canDisable) {\r\n        \/\/ System is in S-Mode but can be taken out of S-Mode\r\n        suggestCompanion = true;\r\n    } else {\r\n        \/\/ System is locked into S-Mode\r\n        suggestCompanion = false;\r\n    }\r\n} else {\r\n    \/\/ System is not in S-Mode\r\n    suggestCompanion = true;\r\n}\r\n<\/pre>\n<pre>\/\/ C++\/CX\r\nusing namespace Windows::System::Profile;\r\n\r\nif (WindowsIntegrityPolicy::IsEnabled) {\r\n    \/\/ System is in S-Mode\r\n    if (WindowsIntegrityPolicy::CanDisable) {\r\n        \/\/ System is in S-Mode but can be taken out of S-Mode\r\n        suggestCompanion = true;\r\n    } else {\r\n        \/\/ System is locked into S-Mode\r\n        suggestCompanion = false;\r\n    }\r\n} else {\r\n    \/\/ System is not in S-Mode\r\n    suggestCompanion = true;\r\n}\r\n<\/pre>\n<pre>\/\/ C++\/WRL\r\n#include &lt;wrl\/client.h&gt;\r\n#include &lt;wrl\/wrappers\/corewrappers.h&gt;\r\n#include &lt;Windows.System.Profile.h&gt;\r\n#include &lt;wil\/result_macros.h&gt;\r\n\r\nnamespace WRL\r\n{\r\n    using namespace Microsoft::WRL;\r\n    using namespace Microsoft::WRL::Wrappers;\r\n}\r\nnamespace ABI\r\n{\r\n    using namespace ABI::Windows::System::Profile;\r\n}\r\n\r\nWRL::ComPtr&lt;ABI::IWindowsIntegrityPolicyStatics&gt; statics;\r\nTHROW_IF_FAILED(::RoGetActivationFactory(\r\n    WRL::HStringReference(RuntimeClass_Windows_System_Profile_WindowsIntegrityPolicy).Get(),\r\n    IID_PPV_ARGS(&amp;statics)));\r\n\r\nboolean isEnabled;\r\nTHROW_IF_FAILED(statics-&gt;get_IsEnabled(&amp;isEnabled));\r\nif (isEnabled) {\r\n    \/\/ System is in S-Mode\r\n    boolean canDisable;\r\n    THROW_IF_FAILED(statics-&gt;get_CanDisable(&amp;canDisable));\r\n    if (canDisable) {\r\n        \/\/ System is in S-Mode but can be taken out of S-Mode\r\n        suggestCompanion = true;\r\n    } else {\r\n        \/\/ System is locked into S-Mode\r\n        suggestCompanion = false;\r\n    }\r\n} else {\r\n    \/\/ System is not in S-Mode\r\n    suggestCompanion = true;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Check the code integrity policy.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-111444","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Check the code integrity policy.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=111444"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111444\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=111444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}