windows - GetVersion/GetVersionEx 已弃用,如何获取 Win8.1 操作系统版本?

标签 windows winapi visual-studio-2013 windows-8.1 minimumosversion

在某些情况下,我想特别了解操作系统的主要/次要版本和内部版本号等。

从 windows 8.1 开始,GetVersionGetVersionEx 已被弃用,说明:

[GetVersion/GetVersionEx may be altered or unavailable for releases after Windows 8.1. Instead, use the Version Helper functions]

没有version helper APIs帮助我获取操作系统版本号,而不是帮助我验证或了解我的版本是否相同或高于某些提到的版本。可以做什么?

最佳答案

API GetVersionEx()继续在 Windows 8.1+ 中工作,但 Microsoft 已更改其功能。来自 MSDN(强调我的):

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 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 please refer to Targeting your application for Windows 8.1.

您需要做的是将正确的 GUID 添加到您的应用程序 (.exe/.dll) 二进制文件(通过 list XML 信息)。换句话说,如果您明确声明您的应用程序支持 8.1,GetVersionEx() 将在 Windows 8.1 上运行时返回正确的信息。如果您不这样做,GetVersionEx() 将对您撒谎。

参见 Targeting your application For Windows 8.1获取 GUID 列表。 还有 covered here and here .

懒人的 GUID 列表

  • Vista/Server 2008:{e2011457-1546-43c5-a5fe-008deee3d3f0}
  • Windows 7/Server 2008 R2:{35138b9a-5d96-4fbd-8e2d-a2440225f93a}
  • Windows 8/Server 2012:{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}
  • Windows 8.1/Server 2012 R2:{1f676c76-80e1-4239-95bb-83d0f6d0da78}
  • Windows 10/Server 2016:{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}

至于 Windows Server 2019,我不确定是否发布了新的 GUID。如果你知道更多请评论!

关于windows - GetVersion/GetVersionEx 已弃用,如何获取 Win8.1 操作系统版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27246562/

相关文章:

python - 为什么我的 Python 脚本文件夹中有多个 pip 版本?

.net - 解释一下这个功能可能会出现什么问题(如果有的话)

delphi - 我怎样才能等到外部进程完成?

c++ - 将 OpenGL 与 Visual Studio 2013 Express 结合使用

c# - Visual Studio 引用突出显示不会禁用

javascript - Visual Studio 2013 JavaScript/TypeScript 奇怪的缩进行为

c - CGO对“TIFFGetField”的 undefined reference

java - mac 中的 processWindowEvent

windows - 如何终止当前使用 Windows localhost 上的端口的进程?

c++ - 未找到 regdeletekey 返回文件