August 7th, 2025
like4 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.

Single comment
  • Igor Levicki

    What happened to plain C version?

    • alan robinson

      Or, MFC!

      (probably would work out to be the same, more or less?)

    • Michael Taylor

      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
      • Igor Levicki

        @Raymond Chen

        Your sample code seems to be incorrect / incomplete. The fine manual suggests to also check:

        <code>

        Because apparently a boolean flag named <code> doesn't mean you can actually do that *rolls eyes* -- so typical of Microsoft devs to make stuff like that, totally not your fault for missing it.

        I think this is a perfect case where a single enum should have been used instead of two boolean flags -- something like SModeControl with { Disabled = 0, BlockedByPolicy, Enabled } where you only have to compare the value to Enabled to know whether you can change it.

        Read more
      • Igor Levicki

        What I meant is “What happened to plain C version of example code“. If I remember correctly Raymond was quite adamant about always using the simplest possible code for examples.

      • LB · 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.