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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2665755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 00:16:24  来源:igfitidea点击:

How can i determine the version of the Windows SDK installed on my computer?

c++visual-studio-2008-sp1winapi

提问by Matt

I've very recently decided to teach myself c++and win32programming after learning vb.net, and I've got a very simple question:

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

How can I determine what version of the Windows SDKis installed on my computer?

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

I'm asking so I can install the latest version if it isn't installed already, before I start playing around with c++. I'm using Microsoft Visual Studio 2008 SP1as my IDE.

在我开始使用c++. 我正在Microsoft Visual Studio 2008 SP1用作我的IDE.

采纳答案by Richard

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.

应该管用。很可能会安装多个版本,对于一个构建来说正确的版本只能由该项目指定。

回答by Day

The current version of the Windows SDK is stored in the CurrentVersionvalue 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

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")

enter image description here

在此处输入图片说明

回答by Bruce Dawson

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. For instance:

如果您需要在编译时确定正在使用的 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

In most cases this should not be necessary because a product should be designed to build with a particular platform SDK. But for some large products there may be a desired to support multiple platform SDKs. 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. This technique can also be used to give helpful error messages if the required SDK version is not installed.

在大多数情况下,这不是必需的,因为产品应该设计为使用特定平台 SDK 构建。但对于一些大型产品,可能需要支持多平台 SDK。这在从一个迁移到另一个时特别有用。如果头文件中存在错误(例如 bthledef.h 的 Windows 8.1 SDK 版本中的虚假“#pragma pop”),则您可能需要解决此错误,但在使用 Windows 10 SDK 时不包括解决方法或更高。如果未安装所需的 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. As of the Windows 10.0.17763.0 SDK NTDDI_WIN10_RS5 is now defined. So, write code like this:

请注意,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

回答by T.Todua

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

回答by Casey Kuball

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. The menu should give you a dropdown list of available Windows SDK versions.

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