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.
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; }
Maybe I’m missing something big, but I find the following code much more understandable…
Or it ‘s just a matter of taste, anyway…
What happened to plain C version?
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...
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.