Windows 8.1 GetVersionEx返回6.2.9200 的问题!

http://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx

http://tunps.com/getversionex-on-windows-8-1-return-6-2-9200


某程序需要判断当前Windows系统的版本号。Windows系统的版本号格式为:majorVersion.minorVersion.BuildNumber.

Windows 8 RTM的版本号的6.2.9200 Windows 8.1 Preview的版本好是6.3.9431

使用以下代码在Win8下面运行正常的显示为6.2.9200 , 但是接下来在Win8.1下面测试尽然还是6.2.9200。
而通过Win8.1自带的命令行systeminfo(采用WMI方式)返回的是正确的版本号

google了一下,MSDN论坛上有个帖子遇到同样的问题。实际上这个问题并非bug,而是微软有意为之。
如果程序的目标运行平台不需要支持Win8.1,那么GetVersion(Ex)就给你返回6.2,
除非通过App manifests方式指定程序支持Win8.1系统:


<exe>.manifest
<?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 app 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 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>

在Win8.1系统以后GetVersion(Ex)被放到兼容层(shim)里面,这样GetVersion(Ex)并不一定会返回系统真实的版本号。

取而代之可以采用VersionHelpers方式获取真实的系统版本号。

C++
#include <VersionHelpers.h>

    if (!IsWindows8OrGreater())
    {
       MessageBox(NULL, "You need at least Windows 8", "Version Not Supported", MB_OK);
    }

原文地址:https://www.cnblogs.com/FCoding/p/3429159.html