MSVC OSVersion 返回不正确的版本
MSVC OSVersion returning incorrect version
在我的开发机器上运行Windows 10。尝试获取操作系统版本以返回主要版本 10。尝试了这个,也通过System::Environment::OSVersion->VersionString
尝试了环境变量。两人都在回归Microsoft Windows NT 6.2.9200
.在Windows 7机器上测试了可执行文件,我得到了6.1.*
(正确(。
在Powershell中运行它,我得到正确的结果:
PS Z:> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 14393 0
我在Visual Studio中使用相同的环境变量逻辑编写了一个测试C++程序...
#include <Windows.h>
#include <iostream>
using namespace std;
int main(int argc, char **argv, char** envp) {
printf("Current compiler version is ... %dn", _MSC_VER);
printf("Current compiler full version is ... %dn", _MSC_FULL_VER);
printf("Current OSVersion is ... %snn", System::Environment::OSVersion->VersionString);
char** env;
for (env = envp; *env != 0; env++)
{
char* thisEnv = *env;
printf("%sn", thisEnv);
}
cin.ignore();
cin.ignore();
return 0;
}
结果它(我不会打印除一个之外的所有环境变量(...
Current compiler version is ... 1900
Current compiler full version is ... 190024215
Current OSVersion is ... Microsoft Windows NT 6.2.9200.0
...
OS=Windows_NT
上述测试程序配置了目标平台作为10.0.14393.0
。
为什么它认为我的操作系统是Windows 8?
规格:
- 视窗 10 版本
- 10.0.14393 内部版本 14393
- Visual Studio 2015 (C++ 项目(
- 目标平台 10.0.14393.0
- Powershell 版本 5.1
这是
设计使然,因为GetVersionEx
和VerifyVersionInfo
函数在Windows 8.1或更高版本上为所有Win32桌面应用程序默认启用"版本谎言"。
适当兼容性 GUID 的 EXE 添加嵌入式清单来控制"版本谎言"的应用:
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 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}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>
请参阅 MSDN 和 Manifest Madness
相关文章:
- 使用2个键的cpp-stl::优先级队列排序不正确
- 正弦级数方程计算不正确
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 密码登录程序将永远循环并显示不正确的结果
- 在C++中返回不正确的楼层函数值
- 形状对象的旋转和缩放不正确C++
- C++ 读取文件读取文件不正确
- 关于类的 Python 文档 - 对C++的引用不正确
- 特征 LLT 模块给出不正确的结果?
- glibcxx STL 在实现 std::valarray::sum() 时是否不正确?
- 如果语句逻辑不正确
- 来自逆 vp 矩阵和相机位置的光线方向不正确
- 不正确的操作数类型 MSVC
- 数组填充了不正确的值
- 我是否不正确地集中了这些字符数组?
- 为什么除非我使用 cout,否则我的值不正确?
- 三元运算符 '?:' 在 4.9.0 之前的 GCC 版本中推断出不正确的类型?
- MSVC OSVersion 返回不正确的版本
- OpenGL 编译使用不正确的版本
- 由于不正确的Direct X版本导致的编译错误