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;
}
相关推荐
郝学胜_神的一滴20 小时前
CMake 034:生成器表达式:解耦构建时序、精简分支逻辑的终极利器
c++·cmake
见过夏天1 天前
C++ 基础入门完全指南
c++
用户805533698033 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
BadBadBad__AK3 天前
线段树维护区间 k 次方和
c++·数学·算法·stl
卷无止境4 天前
Eigen 库如何借助 OpenMP 加速计算
c++·后端
卷无止境4 天前
OpenMPI、MPICH 与 OpenMP:关系、核心概念与架构全解
c++·后端
郝学胜_神的一滴5 天前
CMake 30:循环语法全解|foreach_while双循环精讲、迭代技巧与实战避坑指南
c++·cmake
卷无止境7 天前
C++ 的Eigen 库全解析
c++
卷无止境7 天前
现代 C++特性大盘点:一门脱胎换骨的老语言
c++·后端
郝学胜_神的一滴7 天前
CMake 27:缓存变量的特性、语法、类型与实操全解
c++·cmake