【问题标题】:Same version number for different Windows versions不同的 Windows 版本使用相同的版本号
【发布时间】:2015-06-14 10:15:40
【问题描述】:

在这个page,有这样的东西:

Windows Server 2008 6.0

Windows Vista 6.0

GetVersionEx()返回版本号(即6.0),但正如你所见,这个数字可以映射到两个不同的Windows版本!

那么有没有办法确切知道我的 Windows 版本是什么?

【问题讨论】:

  • 那是因为它实际上是同一个版本。相同的内核,只是调整不同。使用 OSVERSIONINFOEX.wProductType 进行区分。

标签: c winapi


【解决方案1】:

GetVersionInfoEx API 返回一个完全填充的OSVERSIONINFOEX structure(如果请求)。 documentation 包含一个完整的表格,以及如何区分具有相同版本号的操作系统版本的说明:

下表总结了受支持的 Windows 版本返回的值。使用标有“其他”的列中的信息来区分具有相同版本号的操作系统。

对于您的特定示例,您需要将OSVERSIONINFOEX.wProductTypeVER_NT_WORKSTATION 进行比较。如果相等,则您使用的是 Windows Vista,否则您使用的是 Windows Server 2008。

要获得适用于 Windows 8.1 及更高版本的可靠结果,您的应用程序需要显示为兼容。有关为 Windows 8.1 及更高版本显示应用程序的说明,请访问Targeting your application for Windows

清单文件示例:

<?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>

【讨论】:

    【解决方案2】:

    一些version numbers 对应于Windows 的客户端和服务器版本。

    您可以使用IsWindowsServer 函数来区分 Windows 的客户端和服务器版本,将其与版本号结合起来,您就有了确切的版本。

    但是,如果您尝试检测是否支持某些功能,则不推荐检查版本号,您可能希望使用LoadLibraryGetProcAddress 来检查功能。

    【讨论】:

    • 但是如何区分“Windows Server 2003”和“Windows Server 2003 R2”呢?
    • @user4582812 通过检查您真正关心的差异,而不是检查版本号。
    • @user4582812 如果你真的想这样做,那么看看Win32_OperatingSystem 类。所有信息都在那里,包括内部版本号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-02
    • 2013-05-24
    • 2023-04-11
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多