[英]Same version number for different Windows versions
In this page , there is something like this: 在此页面中 ,是这样的:
Windows Server 2008 6.0 Windows Server 2008年6.0
Windows Vista 6.0 Windows Vista 6.0
GetVersionEx()
returns the version number (ie 6.0), but as you can see, this number can map to two different Windows versions! GetVersionEx()
返回版本号(即6.0),但是如您所见,该数字可以映射到两个不同的Windows版本!
So is there's a way to know exactly what Windows version I have? 那么有没有一种方法可以确切地知道我拥有哪个Windows版本?
The GetVersionInfoEx API returns a fully populated OSVERSIONINFOEX structure (if requested). GetVersionInfoEx API返回一个完全填充的OSVERSIONINFOEX结构 (如果需要)。 The documentation contains a complete table, alongside instructions on how to distinguish between OS versions with identical version numbers: 该文档包含一个完整的表格,以及有关如何区分具有相同版本号的OS版本的说明:
The following table summarizes the values returned by supported versions of Windows. 下表总结了受支持的Windows版本返回的值。 Use the information in the column labeled "Other" to distinguish between operating systems with identical version numbers. 使用标记为“其他”的列中的信息来区分版本号相同的操作系统。
For your particular example you would need to compare OSVERSIONINFOEX.wProductType
against VER_NT_WORKSTATION
. 对于您的特定示例,您需要将OSVERSIONINFOEX.wProductType
与VER_NT_WORKSTATION
进行比较。 If it is equal, you're on Windows Vista, otherwise you are on Windows Server 2008. 如果相等,则您使用的是Windows Vista,否则,您使用的是Windows Server 2008。
To get reliable results for Windows 8.1 and above, your application needs to be manifested to be compatible. 为了在Windows 8.1及更高版本上获得可靠的结果,您的应用程序必须证明是兼容的。 Instructions on manifesting an application for Windows 8.1 and above are available at Targeting your application for Windows . 针对Windows 8.1及更高版本显示应用程序的说明可在“ 针对Windows应用程序定位”中找到。
Sample manifest file: 清单文件示例:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity
type="win32"
name=SXS_ASSEMBLY_NAME
version=SXS_ASSEMBLY_VERSION
processorArchitecture=SXS_PROCESSOR_ARCHITECTURE
/>
<description> my foo exe </description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"
/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
</assembly>
Some version numbers correspond to both a client and server release of Windows. 一些版本号与Windows的客户端和服务器版本均对应。
You can use the IsWindowsServer function to distinguish between client and server versions of Windows, combine that with the version number and you have the exact version. 您可以使用IsWindowsServer函数区分Windows的客户端版本和服务器版本,并将其与版本号结合使用,即可获得确切的版本。
However if you're trying to detect whether some feature is supported, checking the version numbers isn't the recommended way, you may want to use LoadLibrary
and GetProcAddress
instead to check for features. 但是,如果您尝试检测是否支持某些功能,则不建议使用检查版本号的方法,您可能想使用LoadLibrary
和GetProcAddress
来检查功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.