如何确定计算机上安装的Windows SDK的版本?

时间:2010-04-19 07:20:36

标签: c++ visual-studio-2008-sp1 winapi

我最近决定在学习c++后自学win32vb.net编程,我有一个非常简单的问题:

如何确定我的计算机上安装了Windows SDK的版本?

我问的是,如果我没有安装最新版本,我可以安装最新版本,然后开始使用c++。我使用Microsoft Visual Studio 2008 SP1作为IDE

5 个答案:

答案 0 :(得分:40)

至少在英语语言环境中:

dir "%ProgramFiles%\Microsoft SDKs\Windows"

应该有效。很可能会安装多个版本,只有一个版本才能由该项目指定。

答案 1 :(得分:28)

当前版本的Windows SDK存储在以下注册表项的CurrentVersion值中:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows CurrentVersion

可以使用此PowerShell单行检索它:

$(Get-Item "hklm:\SOFTWARE\Microsoft\Microsoft SDKs\Windows").GetValue("CurrentVersion")

enter image description here

答案 2 :(得分:28)

如果您需要在编译时确定正在使用的Windows SDK的主要操作系统版本,那么您可以使用在ntverp.h中定义的VER_PRODUCTBUILD宏。例如:

#include <ntverp.h>
#if VER_PRODUCTBUILD > 9600
// Windows 10+ SDK code goes here
#else
// Windows 8.1- SDK code goes here
#endif

在大多数情况下,这不应该是必要的,因为产品应该设计为使用特定平台SDK构建。但对于某些大型产品,可能需要支持多平台SDK。当从一个迁移到另一个时,这可能特别有用。如果头文件中存在错误(例如伪造的#34; #pragma pop&#34;在Windows 8.1 SDK版本的bthledef.h中),那么您可能需要解决此错误,但不包括解决方法时使用Windows 10 SDK或更高版本。如果未安装所需的SDK版本,此技术还可用于提供有用的错误消息。

请注意,VER_PRODUCTBUILD仅提供主要的操作系统版本信息,例如8.1和10.这意味着VER_PRODUCTBUILD越来越无用,因为它不会随着Windows 10的更新而改变。因此,更可能看到的是sdkddkver.h和NTDDI_WIN10_ *宏。从Windows 10.0.17763.0 SDK开始,现在定义了NTDDI_WIN10_RS5。所以,写这样的代码:

#include <sdkddkver.h>
#if !defined(NTDDI_WIN10_RS5)
    #error Windows 10.0.17763.0 SDK is required
#endif

答案 3 :(得分:4)

对于最新版本,请在此regedit键下进行检查:

    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="LauncherButton" parent="TextAppearance.AppCompat.Medium">
        <item name="android:textColor">?colorAccent</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_centerHorizontal">true</item>
        <item name="android:textAllCaps">false</item>
    </style>

或以下:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits

答案 4 :(得分:-1)

如果已安装Visual Studio,则可以打开Visual Studio解决方案(或自己创建一个解决方案),然后在解决方案资源管理器中右键单击该解决方案,然后选择Retarget Solution。菜单应该会为您提供可用Windows SDK版本的下拉列表。