c++ - Windows 10 VersionHelper.h

标签 c++ visual-c++

我需要将客户端计算机上运行的 Windows 版本存储在一个变量中。我在使用 VersionHelper.h 时遇到问题,使用 Windows 10 的机器显示为 Windows 8,我该如何解决这个问题?

我使用的是 Visual Studio 2015,目标平台版本:10.0.10586.0

if (IsWindows7SP1OrGreater())
{
    strcpy_s(this->OS_Detect, "Windows 7 SP1");
}

if (IsWindows8OrGreater())
{
    strcpy_s(this->OS_Detect, "Windows 8");
}

if (IsWindows8Point1OrGreater())
{
    strcpy_s(this->OS_Detect, "Windows 8.1");
}

if (IsWindows10OrGreater())
{
    strcpy_s(this->OS_Detect, "Windows 10");
}

返回装有 windows 10 = "Windows 8"的机器

最佳答案

你必须包括 <compatibility> 应用程序 list 文件中的标志

另见 Targeting your application for Windows

如果您还没有 list 文件,请使用记事本创建一个名为“appname.exe.manifest”的文件

添加以下内容:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
      <!-- Windows 10 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!-- Windows 8.1 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <!-- Windows 8 -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <!-- Windows Vista -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!-- Windows 7 -->
    </application>
  </compatibility>

</assembly>

接下来,将此文件拖放到您的 Visual Studio 2015 项目中。

对于较旧的 VS 版本,您必须在项目 -> list 部分中指定文件名

关于c++ - Windows 10 VersionHelper.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35474237/

相关文章:

windows - Windows下如何查询用户的session id?

c++ - 为什么 C++ 中的分号似乎隐式处理错误? [tldr : they don't]

c++ - 将文件中的字节转换为整数 C++

c++ - 转换大约 150mb 字符串的快速方法

c++ - 为什么 std::stringstream 在静态内联时不能默认构造?

c++ - 如何在mingw中进行libwinpthread-1.dll的静态链接?

c++ - MSVC : Why are functions containing basic QString operations not inlined?

c++ - 使用 fstream C++ 读取字节

c++ - 从 Windows 上的 Qt Creator 进入 Qt 源代码(不是从源代码构建的)

c++ - 如何从成员函数返回私有(private)字符数组?