首页 技术 正文
技术 2022年11月16日
0 收藏 793 点赞 4,995 浏览 1865 个字

近期赶时髦升级了win10,用着挺爽。但是某天在测试一个bug时发现要对win10做特殊处理,于是直接调用了GetVersionEx,并取出版本号进行判断,但是发现得到的版本竟然是6.2。当时就被雷到了,然后看了我们的其它产品中相关功能,皆获取的是6.2。

在搜索一会儿之后,发现这是微软故意做的设定,GetVersionEx函数可能在Win8.1之后会取消,推荐程序员们使用Version Helper APIs ,所以在8.1之后的系统中此函数的行为改变了,如果程序没有加上正确的manifested以表明此程序兼容新系统,则只能得到6.2这个版本号。

下面说说,需要如何添加一个正确的manifest,也可以去MSDN上直接看原始文档

首先,如果原来程序就已经设置了附加一个额外的manifest文件,则直接在原来的manifest里的assembly根节点里加一段兼容指示:

win10 系统下获取系统版本号为6.2的问题(manifest如何写)

 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- 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}"/>
</application>
</compatibility>

win10 系统下获取系统版本号为6.2的问题(manifest如何写)

如果原来没有一个manifest文件,则可以在工程的某目录创建一个 xxx.manifest文件,里面写上以下内容,当然内容中的工程名称可以随意,并没有强制,只要确保compatibility节点的值不变就可以了:

win10 系统下获取系统版本号为6.2的问题(manifest如何写)

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.5.0.0" processorArchitecture="X86" name="Microsoft.Windows.工程名称" type="win32"/>
<description>工程名称</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- 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}"/>
</application>
</compatibility>
</assembly>

win10 系统下获取系统版本号为6.2的问题(manifest如何写)

然后在vs工程属性里找到“清单工具->输入和输出->附加清单文件”里填入manifest文件的相对路径,然后重新链接,你的程序就可以正常的使用GetVersionEx了。但出了新系统之后,估计还是要重新改下manifest以兼容新的系统。

http://www.cnblogs.com/k1988/p/4727757.html#3291657

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918