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;
}
相关推荐
hhhwx6661 天前
Linux学习记录--利用信号量来调度共享资源(2)
linux·c语言·c++·学习
1白天的黑夜11 天前
队列+宽搜(BFS)-662.二叉树最大宽度-力扣(LeetCode)
c++·leetcode·宽度优先·队列
yihai-lin1 天前
Rust/C/C++ 混合构建 - Cmake集成Cargo编译动态库
c语言·c++·rust
m0_552200821 天前
《UE5_C++多人TPS完整教程》学习笔记59 ——《P60 投射物武器(Projectile Weapons)》
c++·游戏·ue5
攻城狮7号1 天前
【AI时代速通QT】第七节:Visual Studio+Qt 开发指南
c++·qt·跨平台·visual studio·qt vs tools
我要成为c嘎嘎大王1 天前
【C++】模版专题
c++·算法
我要成为c嘎嘎大王1 天前
【C++】内存管理
开发语言·c++
艾莉丝努力练剑1 天前
【C++STL :string类 (二) 】从接口应用到内存模型的全面探索
linux·开发语言·c++·经验分享
什么半岛铁盒1 天前
C++项目:仿muduo库高并发服务器
linux·服务器·开发语言·c++
轩情吖1 天前
Qt常用控件之QWidget(三)
开发语言·c++·qt·控件·cursor·qwidget·windowopacity