简体   繁体   English

如何获取安装的 Windows SDK 版本?

[英]How to get installed Windows SDK version?

How can I determine what version of the Windows SDK is installed on my computer?如何确定我的计算机上安装了哪个版本的Windows SDK

I'm asking so I can install the latest version if it isn't installed already.我在问,如果尚未安装最新版本,我可以安装它。

On English locale at least:至少在英语语言环境中:

dir "%ProgramFiles%\Microsoft SDKs\Windows"

should work.应该管用。 It is quite likely that there will be multiple versions installed, which is the right one for an one build can only be specified by that project.很可能会安装多个版本,对于一个构建来说正确的版本只能由该项目指定。

The current version of the Windows SDK is stored in the CurrentVersion value of the following registry key: Windows SDK 的当前版本存储在以下注册表项的CurrentVersion值中:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows CurrentVersion

and it can be retrieved using this PowerShell one-liner:并且可以使用这个 PowerShell one-liner 来检索它:

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

在此处输入图片说明

If you need to determine, while compiling, what major OS version of the Windows SDK is being used then you can use the VER_PRODUCTBUILD macro, which is defined in ntverp.h.如果您需要在编译时确定正在使用的 Windows SDK 的主要操作系统版本,那么您可以使用在 ntverp.h 中定义的 VER_PRODUCTBUILD 宏。 For instance:例如:

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

In most cases this should not be necessary because a product should be designed to build with a particular platform SDK.在大多数情况下,这不是必需的,因为产品应该设计为使用特定平台 SDK 构建。 But for some large products there may be a desired to support multiple platform SDKs.但对于一些大型产品,可能需要支持多平台 SDK。 This can be particularly useful when migrating from one to another.这在从一个迁移到另一个时特别有用。 If there is a bug in a header file (such as the bogus "#pragma pop" in the Windows 8.1 SDK version of bthledef.h) then you may need to workaround this bug, but not include the workaround when using the Windows 10 SDK or higher.如果头文件中存在错误(例如 bthledef.h 的 Windows 8.1 SDK 版本中的虚假“#pragma pop”),则您可能需要解决此错误,但在使用 Windows 10 SDK 时不包括解决方法或更高。 This technique can also be used to give helpful error messages if the required SDK version is not installed.如果未安装所需的 SDK 版本,此技术还可用于提供有用的错误消息。

Note that VER_PRODUCTBUILD only gives major OS version information, such as 8.1 versus 10. That means that VER_PRODUCTBUILD is increasingly useless as it doesn't change with the updates to Windows 10. Therefore the more likely thing to look at is sdkddkver.h and the NTDDI_WIN10_* macros.请注意,VER_PRODUCTBUILD 仅提供主要操作系统版本信息,例如 8.1 与 10。这意味着 VER_PRODUCTBUILD 越来越无用,因为它不会随着 Windows 10 的更新而改变。因此,更有可能查看的是 sdkddkver.h 和NTDDI_WIN10_* 宏。 As of the Windows 10.0.17763.0 SDK NTDDI_WIN10_RS5 is now defined.从 Windows 10.0.17763.0 SDK NTDDI_WIN10_RS5 开始,现已定义。 So, write code like this:所以,写这样的代码:

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

For latest versions, check under this regedit key:对于最新版本,请在此注册表项下检查:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits

or under:或以下:

C:\Program Files (x86)\Microsoft SDKs\Windows Kits

If you have Visual Studio installed, you can open a Visual Studio solution (or create one yourself), then right-click the solution in the solution explorer, and select Retarget Solution .如果您安装了 Visual Studio,您可以打开一个 Visual Studio 解决方案(或自己创建一个),然后在解决方案资源管理器中右键单击该解决方案,并选择Retarget Solution The menu should give you a dropdown list of available Windows SDK versions.该菜单应为您提供可用 Windows SDK 版本的下拉列表。

Look under Control Panel / Uninstall a program .查看控制面板/卸载程序 "Windows Software Development Kit - Windows XXXX" (where XXXX is the version). “Windows 软件开发工具包 - Windows XXXX”(其中 XXXX 是版本)。 It will be listed amongst all the other software you have installed on your machine.它将列在您机器上安装的所有其他软件中。

如果您安装了 vs2019(或任何其他版本),您可以在“桌面开发部分”的工作负载下查看 Windows SDK 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM