【问题标题】:How to detect Windows 10 S?如何检测 Windows 10 S?
【发布时间】:2018-05-02 06:31:22
【问题描述】:

Windows 10 S 是一个特殊的 Windows 版本,它是streamlined for security and superior performance。基本上你只能从 Microsoft Store 安装应用程序。

您可以通过桌面桥将普通桌面应用程序交付到应用商店,这样本身就不是什么大问题。但是,Windows 10 S 对应用商店应用施加了额外的限制,这可能会导致它们在启动时崩溃。

我收到了来自商店申请审核结果的反馈。

应用策略:10.1.2.1 功能不准确:Windows 10S

开发者须知:

您的应用无法在 Windows 10 S 和该应用上运行 终止,恕不另行通知用户。无法在 Windows 上运行的应用 10 S 必须支持正常关机。

重现步骤: 1. 在 Windows 10S 上启动应用程序。 2. 请注意,您的应用无法在 Windows 10 S 上运行,应用会在不通知用户的情况下终止。

请务必针对 Windows 10 S 测试您的应用: https://docs.microsoft.com/windows/uwp/porting/desktop-to-uwp-test-windows-s 测试设备:Windows 10 桌面版

所以基本上我需要做的是检测 Windows 10 S 并通知用户它不受支持。

【问题讨论】:

  • 检查this问题。
  • 我还添加了不带 WMP 的 N 版的值,因为您来自波兰并且可能会遇到此类问题来检测此类版本。
  • 出于好奇,您知道您的应用程序在做什么导致崩溃吗?
  • @PeterTorr-MSFT 我认为这是因为我使用System.Diagnostics.Process.Start 来启动我的应用程序以外的进程。这也是package sanity test 的建议:github.com/PawelTroka/Computator.NET/issues/129
  • 啊,是的,你不能在 10 S 上运行 CMD 或 PowerShell 脚本。谢谢!

标签: c# .net uwp windows-10 desktop-bridge


【解决方案1】:

使用GetProductInfo Win32 API 调用并检查返回值PRODUCT_CLOUD (0x000000B2) 和PRODUCT_CLOUDN (0x000000B3)。这 2 个值是 Windows 10 S 的 SKU 检测代码。

【讨论】:

  • 这种方法可能很快就会失效,因为微软已经宣布他们打算让 10S 成为一种模式而不是单独的产品。如果他们这样做,那么当用户切换该选项时,SKU 可能会保持不变。
  • @jbcarpen 我们得等最终产品和SDK,看看微软是如何为所有SKU实现这个S模式的。
  • 我很好奇这是否仍然有效? (如果没有我的商店应用通过认证,我无法立即尝试。)
  • 是的,我可以确认,我刚刚在Win10 S 机器上测试得到的pdwReturnedProductType0xB2
  • @c00000fd 这是预期的。对于 1803 (17133.1),您可以通过在 HKLM\System\CurrentControlSet\Control\CI\Policy 下创建一个名为 WindowsLockdownTrialMode 的新 DWORD 将任何版本转换为 S 模式。所以要检测这个模式查询值。
【解决方案2】:

我只是把它扔在那里,作为另一种想法。这完全没有记录!

我纯粹是偶然了解到,如果您尝试ShellExecuteEx10 S 中不允许使用的 Windows 默认应用程序之一,例如 %WinDir%\System32\cmd.exe,它将失败并显示错误代码 ERROR_SYSTEM_NEEDS_REMEDIATION(或 @ 987654325@),我没有看到任何其他电话返回。

【讨论】:

    【解决方案3】:

    受magicandre1981 检查SKU 解决方案的启发,我将其作为具体解决方案实施。它包含在 Windows 10 中弃用 GetVersionEx() 的解决方法,并包含对 Windows 10 S 开发模式的检查,以便进行适当的测试。

    一项免责声明是,此检查在我的环境(真正的 10 S 和开发模式)中按预期工作。但是最终用户报告说检查不可靠,我无法验证最终用户是否真的运行 10 S 或只是认为他这样做。不过它通过了 Microsoft 的审核流程。

    运行检查的 C++ 控制台应用程序示例:

    // 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");
    }
    

    【讨论】:

      【解决方案4】:

      如果 Windows 10 1803 或更新版本,请检查以下 DWORD 注册表值:

      • 注册表项(路径):HKLM\System\CurrentControlSet\Control\CI\Policy
      • 注册表值名称:SkuPolicyRequired
      • 注册表值 (DWORD):1

      (来源:https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-codeintegrity-skupolicyrequired

      1803 之前的 Windows 10 版本上,Windows 10 S(和 Windows 10 S N)是它们自己的 SKU。要检查这一点,请使用 WMI 查询以下内容: Win32_OperatingSystem -> OperatingSystemSKU 并查找整数值 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 脱机)将设备置于制造模式,然后启动计算机。参考见:https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-10-s-manufacturing-mode

      假设设备处于制造模式并且您可以访问命令提示符,以下是查询 S 模式/Windows 10 S/Windows 10 S N 的几种方法:

      对于 Windows 10 1803 及更新版本,查询 S 模式的一种简单方法是在命令提示符处键入以下内容:

      reg 查询 HKLM\SYSTEM\CurrentControlSet\Control\CI\Policy /v SkuPolicyRequired

      (如果您收到 系统无法找到指定的注册表项或值的消息,或者如果您收到 REG_DWORD 以外的结果 >0x1,则 S 模式未启用

      对于 1803 之前的 Windows 10 版本,在命令提示符处查询此内容的简单方法是键入:

      wmic os 获取操作系统库

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-20
        • 1970-01-01
        相关资源
        最近更新 更多