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 小时前
Effective C++ 条款04:确定对象被使用前已先被初始化
java·linux·开发语言·c++·嵌入式开发
不想写代码的星星1 小时前
std::move 根本不移动,就像老婆饼里没有老婆
c++
redaijufeng1 小时前
C++雾中风景7:闭包
c++·算法·风景
小欣加油2 小时前
leetcode287寻找重复数
数据结构·c++·算法·leetcode
思麟呀2 小时前
C++11 核心特性(三):强类型枚举、static_assert 与 std::tuple
开发语言·c++
一拳一个呆瓜2 小时前
【STL】C++程序的启动与终止
c++·stl
凡人叶枫3 小时前
Effective C++ 条款07:为多态基类声明 virtual 析构函数
linux·c语言·开发语言·c++
凡人叶枫3 小时前
Effective C++ 条款10:令 operator= 返回一个 reference to *this
java·linux·服务器·开发语言·c++·effective c++
王老师青少年编程3 小时前
2026年全国青少年信息素养大赛算法应用主题赛(C++赛项-复赛模拟卷6:文末附答案)
c++·答案·模拟卷·复赛·2026年·青少年信息素养大赛·算法应用主题赛
视觉小萌新3 小时前
C++利用libmicrohttpd制作交互网页端——C1
java·c++·交互