August 7th, 2025
like2 reactions

How can I detect that Windows is running in S-Mode?

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?

You can detect S-Mode by using the Windows.System.Profile.Windows­Integrity­Policy class.

// C#
using Windows.System.Profile;

if (WindowsIntegrityPolicy.IsEnabled) {
    // System is in S-Mode
    if (WindowsIntegrityPolicy.CanDisable) {
        // System is in S-Mode but can be taken out of S-Mode
        suggestCompanion = true;
    } else {
        // System is locked into S-Mode
        suggestCompanion = false;
    }
} else {
    // System is not in S-Mode
    suggestCompanion = true;
}
// C++/WinRT
#include <winrt/Windows.System.Profile.h>

namespace winrt
{
    using namespace winrt::Windows::System::Profile;
}

if (winrt::WindowsIntegrityPolicy::IsEnabled()) {
    // System is in S-Mode
    if (winrt::WindowsIntegrityPolicy::CanDisable()) {
        // System is in S-Mode but can be taken out of S-Mode
        suggestCompanion = true;
    } else {
        // System is locked into S-Mode
        suggestCompanion = false;
    }
} else {
    // System is not in S-Mode
    suggestCompanion = true;
}
// JavaScript
let WindowsIntegrityPolicy = Windows.System.Profile.WindowsIntegrityPolicy;

if (WindowsIntegrityPolicy.isEnabled) {
    // System is in S-Mode
    if (WindowsIntegrityPolicy.canDisable) {
        // System is in S-Mode but can be taken out of S-Mode
        suggestCompanion = true;
    } else {
        // System is locked into S-Mode
        suggestCompanion = false;
    }
} else {
    // System is not in S-Mode
    suggestCompanion = true;
}
// C++/CX
using namespace Windows::System::Profile;

if (WindowsIntegrityPolicy::IsEnabled) {
    // System is in S-Mode
    if (WindowsIntegrityPolicy::CanDisable) {
        // System is in S-Mode but can be taken out of S-Mode
        suggestCompanion = true;
    } else {
        // System is locked into S-Mode
        suggestCompanion = false;
    }
} else {
    // System is not in S-Mode
    suggestCompanion = true;
}
// C++/WRL
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
#include <Windows.System.Profile.h>
#include <wil/result_macros.h>

namespace WRL
{
    using namespace Microsoft::WRL;
    using namespace Microsoft::WRL::Wrappers;
}
namespace ABI
{
    using namespace ABI::Windows::System::Profile;
}

WRL::ComPtr<ABI::IWindowsIntegrityPolicyStatics> statics;
THROW_IF_FAILED(::RoGetActivationFactory(
    WRL::HStringReference(RuntimeClass_Windows_System_Profile_WindowsIntegrityPolicy).Get(),
    IID_PPV_ARGS(&statics)));

boolean isEnabled;
THROW_IF_FAILED(statics->get_IsEnabled(&isEnabled));
if (isEnabled) {
    // System is in S-Mode
    boolean canDisable;
    THROW_IF_FAILED(statics->get_CanDisable(&canDisable));
    if (canDisable) {
        // System is in S-Mode but can be taken out of S-Mode
        suggestCompanion = true;
    } else {
        // System is locked into S-Mode
        suggestCompanion = false;
    }
} else {
    // System is not in S-Mode
    suggestCompanion = true;
}
Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

4 comments

Sort by :
  • Baltasar García 1 minute ago · Edited

    Maybe I’m missing something big, but I find the following code much more understandable…

    using Windows.System.Profile;
    
    bool s_mode = WindowsIntegrityPolicy.IsEnabled;
    bool unlockable_s_mode = WindowsIntegrityPolicy.CanDisable;
    bool suggestCompanion = !s_mode || (s_mode && unlockable_s_mode);

    Or it ‘s just a matter of taste, anyway…

  • Igor Levicki 2 hours ago

    What happened to plain C version?

    • Michael Taylor 2 hours ago

      Is that even possible? In order to be in S-Mode you have to be running code from the MS Store which means UWP, C++/CX, etc. I don't know that you can build a pure C program that can then be hosted in the MS Store simply because it requires some WRL components which are inherently class-based. I'm not sure how the JS version works though...

      If you're able to run a C program then that would, it seems, imply you are not in S-Mode because you can't turn it off and then back on. However I wonder if the C++/WRL...

      Read more
      • LB 47 minutes ago · Edited

        UWP hasn’t required C++/CX for years now, C++/WinRT has been a pure standard C++ option for a long time and you can adapt it to pure C as well, it’s just more effort. SDL2 is a pure C library that supports UWP for example.