C# 如何检测Windows 10?
Windows 10 S是一个特殊的Windows版本,它是。基本上,您只能从Microsoft应用商店安装应用程序 您可以通过桌面网桥将普通桌面应用程序交付到应用商店,这样本身就不会有大问题。然而,Windows10s对商店应用程序施加了额外的限制,这可能会导致它们在启动时崩溃 我从商店应用程序审查结果中收到了此反馈 应用程序策略:10.1.2.1功能不准确:Windows 10S 发展商须知: 你的应用程序在Windows 10 S和应用程序上无法运行 终止而不通知用户。无法在Windows上运行的应用程序 10秒必须支持正常关机 复制步骤: 1.在Windows 10S上启动应用程序。 2.请注意,您的应用程序无法在Windows 10上运行,应用程序将在不通知用户的情况下终止 请确保在Windows 10 S上测试你的应用程序: 测试设备:Windows 10桌面 因此,基本上我需要做的是检测Windows 10并通知用户它不受支持。使用Win32 API调用并检查返回值C# 如何检测Windows 10?,c#,.net,uwp,windows-10,desktop-bridge,C#,.net,Uwp,Windows 10,Desktop Bridge,Windows 10 S是一个特殊的Windows版本,它是。基本上,您只能从Microsoft应用商店安装应用程序 您可以通过桌面网桥将普通桌面应用程序交付到应用商店,这样本身就不会有大问题。然而,Windows10s对商店应用程序施加了额外的限制,这可能会导致它们在启动时崩溃 我从商店应用程序审查结果中收到了此反馈 应用程序策略:10.1.2.1功能不准确:Windows 10S 发展商须知: 你的应用程序在Windows 10 S和应用程序上无法运行 终止而不通知用户。无法在Windows
PRODUCT_CLOUD
(0x000000B2
)和PRODUCT_CLOUDN
(0x000000B3
)。这两个值是Windows10s的SKU检测代码。我只是把它扔出去,作为另一种想法。这完全是无证的
我完全是偶然地了解到,如果您尝试使用
10 S
中不允许的Windows默认应用程序之一,例如%WinDir%\System32\cmd.exe
,它将失败,并出现错误代码error\u SYSTEM\u NEEDS\u rective
(或15623
)我没有看到任何其他调用返回的消息。受magicandre1981检查SKU的解决方案的启发,我将其作为一个具体的解决方案实现。它包含一个在Windows 10中被弃用的解决方法,并包含一个检查Windows 10的开发模式以允许正确的测试
一个免责声明是,此检查在我的环境(real 10 S和Dev模式)中按预期工作。但是最终用户报告说检查不可靠,我无法验证最终用户是否真的运行了10秒,或者只是认为他运行了10秒。不过,它通过了微软的审查程序
<强> C++中的控制台应用程序,运行检查:>/P>
// Windows10SCheck.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <Windows.h>
// Function to get the OS version number
//
// Uses RtlGetVersion() is available, otherwise falls back to GetVersionEx()
//
// Returns false if the check fails, true if success
bool GetOSVersion(OSVERSIONINFOEX* osversion) {
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEX);
*(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
if (RtlGetVersion != NULL)
{
// RtlGetVersion uses 0 (STATUS_SUCCESS)
// as return value when succeeding
return RtlGetVersion(osversion) == 0;
}
else {
// GetVersionEx was deprecated in Windows 10
// Only use it as fallback
#pragma warning(suppress : 4996)
return GetVersionEx((LPOSVERSIONINFO)osversion);
}
}
// Function to check if the product type is Windows 10 S
//
// The product type values are from: https://stackoverflow.com/a/47368738/959140
//
// Output parameter bool iswin10s indicates if running 10 S or not
//
// Returns false if the check fails, true if success
bool IsWindows10S(bool *iswin10s) {
OSVERSIONINFOEX osinfo;
osinfo.dwOSVersionInfoSize = sizeof(osinfo);
osinfo.szCSDVersion[0] = L'\0';
if (!GetOSVersion(&osinfo)) {
return false;
}
DWORD dwReturnedProductType = 0;
if (!GetProductInfo(osinfo.dwMajorVersion, osinfo.dwMinorVersion, 0, 0, &dwReturnedProductType)) {
return false;
}
*iswin10s = dwReturnedProductType == PRODUCT_CLOUD || dwReturnedProductType == PRODUCT_CLOUDN;
return true;
}
bool IsWindows10SDevMode() {
// Checks for the policy file mentioned in the docs:
// https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-test-windows-s
struct stat buffer;
// x64 applications
std::string filePathName64 = "C:\\Windows\\system32\\CodeIntegrity\\SIPolicy.P7B";
if (stat(filePathName64.c_str(), &buffer) == 0) {
return true;
}
// x86 applications
std::string filePathName86 = "C:\\Windows\\sysnative\\CodeIntegrity\\SIPolicy.P7B";
if (stat(filePathName86.c_str(), &buffer) == 0) {
return true;
}
return false;
}
int main() {
bool is10s = false;
if (!IsWindows10S(&is10s)) {
std::cout << "Windows 10 S check failed";
}
std::cout << "\nIs 10 S: " << (is10s ? "true" : "false");
std::cout << "\nIs 10 S Dev Mode: " << (IsWindows10SDevMode() ? "true" : "false");
}
//Windows10SCheck.cpp:此文件包含“main”函数。程序执行从那里开始并结束。
//
#包括“pch.h”
#包括
#包括
//函数获取操作系统版本号
//
//Uses RtlGetVersion()可用,否则返回GetVersionEx()
//
//如果检查失败,则返回false;如果检查成功,则返回true
bool GetOSVersion(OSVersionInfo*osversion){
NTSTATUS(WINAPI*RtlGetVersion)(LPOSVersionInfo);
*(FARPROC*)&RtlGetVersion=GetProcAddress(GetModuleHandleA(“ntdll”),“RtlGetVersion”);
if(RtlGetVersion!=NULL)
{
//RtlGetVersion使用0(状态\成功)
//作为成功时的返回值
返回RtlGetVersion(osversion)==0;
}
否则{
//GetVersionEx在Windows 10中被弃用
//仅将其用作备用方案
#杂注警告(抑制:4996)
返回GetVersionEx((LPOSVERSIONINFO)osversion);
}
}
//用于检查产品类型是否为Windows 10 S的函数
//
//产品类型值来自:https://stackoverflow.com/a/47368738/959140
//
//输出参数bool iswin10s指示是否运行10秒
//
//如果检查失败,则返回false;如果检查成功,则返回true
bool-IsWindows10S(bool*iswin10s){
OsVersionInfo-osinfo;
osinfo.dwosVersionInfo=sizeof(osinfo);
osinfo.szCSDVersion[0]=L'\0';
如果(!GetOSVersion(&osinfo)){
返回false;
}
DWORD dwReturnedProductType=0;
if(!GetProductInfo(osinfo.dwMajorVersion、osinfo.dwMinorVersion、0、0和dwReturnedProductType)){
返回false;
}
*iswin10s=dwReturnedProductType==PRODUCT|u CLOUD | dwReturnedProductType==PRODUCT|CLOUDN;
返回true;
}
bool IsWindows10SDevMode(){
//检查文档中提到的策略文件:
// https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-test-windows-s
结构统计缓冲区;
//x64应用程序
std::string filePathName64=“C:\\Windows\\system32\\codeignity\\SIPolicy.P7B”;
if(stat(filePathName64.c_str(),&buffer)==0){
返回true;
}
//x86应用程序
std::string filePathName86=“C:\\Windows\\sysnative\\codeignity\\SIPolicy.P7B”;
if(stat(filePathName86.c_str(),&buffer)==0){
返回true;
}
返回false;
}
int main(){
bool为10s=假;
如果(!IsWindows10S(&is10s)){
std::cout如果Windows 10 1803或更新版本,请检查以下DWORD注册表值:
- 注册表项(路径):HKLM\System\CurrentControlSet\Control\CI\Policy
- 注册表值名称:必需
- 注册表值(DWORD):1
(来源:)
在1803年以前的Windows 10版本上,Windows 10 S(和Windows 10 S N)是它们自己的SKU。要检查这一点,请使用WMI查询以下内容:
Win32_操作系统->操作系统
并查找整数值178(Windows 10 S)或179(Windows 10 S N)
无论运行的是哪个版本的Windows 10,查询S模式/Windows 10 S/Windows 10 S N都很棘手,因为cmd、powershell、regedit、reg、wmic和wbemtest等常用工具将被阻止。要启用这些工具,需要通过将注册表项放置到位(使用WinPE脱机)将设备置于制造模式,然后启动计算机。有关参考信息,请参阅:
假设设备处于制造模式,并且您可以访问命令提示符,以下是查询S模式/Windows 10 S/Windows 10 S N的几种方法:
对于Windows 10 1803及更新版本