如何将Win8.1中的操作系统版本作为GetVersion / GetVersionEx弃用?

问题描述 投票:8回答:3

我有一些场景,我想特别了解操作系统主要/次要版本和内部版本号等。

从Windows 8.1开始,GetVersionGetVersionEx已被弃用,声明:

[GetVersion / GetVersionEx可能会在Windows 8.1之后更改或不可用于发布。相反,使用版本助手功能]

没有一个version helper APIs帮助我获得操作系统版本号,而是帮助我验证或了解我的版本是否与上述版本相同或更高。可以做些什么?

windows winapi visual-studio-2013 windows-8.1 minimumosversion
3个回答
4
投票

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

随着Windows 8.1的发布,GetVersionEx API的行为已经改变了它将为操作系统版本返回的值。 GetVersionEx函数返回的值现在取决于应用程序的显示方式。

未显示在Windows 8.1中的应用程序将返回Windows 8 OS版本值(6.2)。一旦应用程序显示给定的操作系统版本,GetVersionEx将始终返回应用程序在将来的版本中显示的版本。要显示Windows 8.1的应用程序,请参阅针对Windows 8.1的应用程序。

您需要做的是将适当的GUID添加到您的应用程序(.exe / .dll)二进制文件(通过清单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。如果您了解更多,请评论!


2
投票

有一个名为GetProductInfo的新函数返回版本信息。

如果您想测试特定版本,您甚至应该使用VerifyVersionInfo

可以轻松创建一个结构来检查特定的OS版本是否正在运行。 VerifyVersionInfo采用版本结构,您可以轻松检查VER_GREATER_EQUAL和VER_LESS_EQUAL

另请注意,如果您在清单的兼容性部分中定义了正确支持的OS条目,则GetVersionEx不会位于Windows 8.1系统上。但它可能在于未来的操作系统版本!

请参阅Targeting your application For Windows 8.1以获取GUID列表。还包括here

应用程序清单的GUID列表

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

-9
投票

检查this article on codeproject.com,它适用于Windows 8:

1)下载.DLL并将其添加到您的项目中。

2)使用此代码获取操作系统信息:

StringBuilder sb = new StringBuilder(String.Empty);
sb.AppendLine("Operation System Information");
sb.AppendLine("----------------------------");
sb.AppendLine(String.Format("Name = {0}", OSVersionInfo.Name));
sb.AppendLine(String.Format("Edition = {0}", OSVersionInfo.Edition));
if (OSVersionInfo.ServicePack!=string.Empty)
sb.AppendLine(String.Format("Service Pack = {0}", OSVersionInfo.ServicePack));
else
sb.AppendLine("Service Pack = None");
sb.AppendLine(String.Format("Version = {0}", OSVersionInfo.VersionString));
sb.AppendLine(String.Format("ProcessorBits = {0}", OSVersionInfo.ProcessorBits));
sb.AppendLine(String.Format("OSBits = {0}", OSVersionInfo.OSBits));
sb.AppendLine(String.Format("ProgramBits = {0}", OSVersionInfo.ProgramBits));

textBox1.Text = sb.ToString();
© www.soinside.com 2019 - 2024. All rights reserved.