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;
}
相关推荐
会周易的程序员1 小时前
aiDgePLC — IEC61131-3 ST PLC 虚拟机调试与运行环境
c++·物联网·虚拟机·st·工业协议·iec61131·梯形图
wuminyu3 小时前
JVM利用io_uring优化堆外内存性能原理剖析
java·linux·c语言·jvm·c++
gumichef3 小时前
第二章:C/C++内存管理
c++·内存管理
小龙报7 小时前
【优选算法】1.搜索插入位置 2.x的平方根
java·c语言·数据结构·c++·python·算法·蓝桥杯
A_humble_scholar7 小时前
Linux(二) C++ TCP/UDP网络编程
linux·网络·c++
SNAKEpc121388 小时前
OpenGL(十五)- 着色器语言GLSL
c语言·c++·线性代数·算法·矩阵·图形渲染·着色器
欧特克_Glodon8 小时前
OpenCV计算机视觉开发入门与实践<六>:OpenCV架构模块简介
c++·人工智能·opencv·计算机视觉
Rabitebla9 小时前
C++11 新特性详解(一):列表初始化、initializer_list 与右值引用
java·开发语言·数据结构·c++·算法·leetcode·list
MC皮蛋侠客9 小时前
TDengine C++ 系列(11):性能模型与调优——从测量到优化
c++·php·tdengine
兔兔兔兔110 小时前
记录C++ 3
开发语言·c++