可用Windows.System.Profile.WindowsIntegrityPolicy
类检测S模式.
//`C#`
using Windows.System.Profile;
if (WindowsIntegrityPolicy.IsEnabled) {
//系统在S模式
if (WindowsIntegrityPolicy.CanDisable) {
//系统在S模式,但可退出S模式
suggestCompanion = true;
} else {
//系统锁在S模式
suggestCompanion = false;
}
} else {
//系统未在S模式
suggestCompanion = true;
}
//`C++/WinRT`
#include <winrt/Windows.System.Profile.h>
namespace winrt
{
using namespace winrt::Windows::System::Profile;
}
if (winrt::WindowsIntegrityPolicy::IsEnabled()) {
//系统在S模式
if (winrt::WindowsIntegrityPolicy::CanDisable()) {
//系统在S模式,但可退出S模式
suggestCompanion = true;
} else {
//系统锁在S模式
suggestCompanion = false;
}
} else {
//系统未在S模式
suggestCompanion = true;
}
//`js`
let WindowsIntegrityPolicy = Windows.System.Profile.WindowsIntegrityPolicy;
if (WindowsIntegrityPolicy.isEnabled) {
//系统在S模式
if (WindowsIntegrityPolicy.canDisable) {
//系统在S模式,但可退出S模式
suggestCompanion = true;
} else {
//系统锁在S模式
suggestCompanion = false;
}
} else {
//系统未在S模式
suggestCompanion = true;
}
//`C++/CX`
using namespace Windows::System::Profile;
if (WindowsIntegrityPolicy::IsEnabled) {
//系统在S模式
if (WindowsIntegrityPolicy::CanDisable) {
//系统在S模式,但可退出S模式
suggestCompanion = true;
} else {
//系统锁在S模式
suggestCompanion = false;
}
} else {
//系统未在S模式
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) {
//系统在S模式
boolean canDisable;
THROW_IF_FAILED(statics->get_CanDisable(&canDisable));
if (canDisable) {
//系统在S模式,但可退出S模式
suggestCompanion = true;
} else {
//系统锁在S模式
suggestCompanion = false;
}
} else {
//系统未在S模式
suggestCompanion = true;
}