C++ 如何检测 Windows 10

标签 c++ windows windows-10

我多年前编写了一个 PC 审计工具,并且一直在更新它。基本功能之一是报告正在审核的 PC 上运行的 Windows 版本,我一直使用 GetVersionEx 调用。

这适用于 Windows 8(包括 Windows 8),但在 Windows 10 下不受支持,实际上 Windows 10 与 Windows 8 一样返回 8.2。 Microsoft 似乎没有引入任何东西作为直接替代,而是建议您检查所需的特定功能而不是查看操作系统,但出于审核目的,我实际上想要操作系统名称。

“扫描仪”是一个必须在非特权帐户下运行的 C++ 程序,因此我认为我没有阅读过其他建议 - 选择系统 DLL 的版本(例如 kernel32.dll)将像这些文件夹一样工作通常用户无法访问。

欢迎任何其他建议/想法!

最佳答案

从 Windows 8.1 开始,GetVersion()GetVersionEx()以应用形式为准:

With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested.

Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases. To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.

较新的 Version Helper functions只是 VerifyVersionInfo() 的包装器.从 Windows 10 开始,它现在也受到表现形式的影响:

Windows 10: VerifyVersionInfo returns false when called by applications that do not have a compatibility manifest for Windows 8.1 or Windows 10 if the lpVersionInfo parameter is set so that it specifies Windows 8.1 or Windows 10, even when the current operating system version is Windows 8.1 or Windows 10. Specifically, VerifyVersionInfo has the following behavior:

  • If the application has no manifest, VerifyVersionInfo behaves as if the operation system version is Windows 8 (6.2).
  • If the application has a manifest that contains the GUID that corresponds to Windows 8.1, VerifyVersionInfo behaves as if the operation system version is Windows 8.1 (6.3).
  • If the application has a manifest that contains the GUID that corresponds to Windows 10, VerifyVersionInfo behaves as if the operation system version is Windows 10 (10.0).

The Version Helper functions use the VerifyVersionInfo function, so the behavior IsWindows8Point1OrGreater and IsWindows10OrGreater are similarly affected by the presence and content of the manifest.

To manifest your applications for Windows 8.1 or Windows 10, see Targeting your application for Windows.

要获得 true 操作系统版本,无论表现形式如何,请使用 RtlGetVersion() , NetServerGetInfo() , 或 NetWkstaGetInfo()反而。它们都报告了准确的操作系统版本,并且不受表现形式的影响(还没有?)。

(微软曾经建议查询系统DLL的文件版本,但他们stopped建议当Windows没有更新系统DLL版本以匹配时。)

关于C++ 如何检测 Windows 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32115255/

相关文章:

c++ - 仅公开派生对象覆盖的函数

c++ - 原始 ICMP 套接字 : recvfrom() not recieving any data

java - 通过命令提示符将java程序安装为Windows服务

docker - 运行docker Windows镜像时无法启动Sonatype Nexus3服务

c# - VisualStateGroup的ViewModel方法事件

c++ - std::filesystem::recursive_directory_iterator 异常

C++ : copy constructor that uses a function with non-const parameters

c++ - 为什么我可以在不包含 STL 的情况下使用 nullptr?

windows - 在 Windows 上将 GitHub 存储库下载为 zip,包括 CRLF

c++ - 如何检索 Objective-C 对象的原始指针值?