2508C++,检测S模式

原文

可用Windows.System.Profile.WindowsIntegrityPolicy类检测S模式.

cpp 复制代码
    //`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;
}
相关推荐
王老师青少年编程34 分钟前
2025年12月GESP(C++二级): 环保能量球
c++·算法·gesp·csp·信奥赛·二级·环保能量球
CoderCodingNo1 小时前
【GESP】C++五级真题(贪心思想考点) luogu-P11960 [GESP202503 五级] 平均分配
开发语言·c++·算法
不会写代码的里奇2 小时前
深入解析ASR技术:从原理到C++高性能实现
c++
CSDN_RTKLIB2 小时前
【类定义系列六】C++17新特性
开发语言·c++
hd51cc2 小时前
MFC文件操作
c++·mfc
春蕾夏荷_7282977253 小时前
Sockets-2.3.9.9 UDP使用实例
c++·udp
GetcharZp4 小时前
拒绝硬编码!C++ 配置文件管理神器 yaml-cpp 实战指南
c++
墨有6664 小时前
C++ string 部分功能详解:迭代器、初始化与常用函数
开发语言·c++
枫叶丹44 小时前
【Qt开发】Qt系统(二)-> 事件分发器
c语言·开发语言·数据库·c++·qt·系统架构
千里马-horse5 小时前
Rect Native bridging 源码分析--AString.h
c++·ts·rn·jsi