zoukankan      html  css  js  c++  java
  • win10 系统下获取系统版本号为6.2的问题

    win10 系统下获取系统版本号为6.2的问题

     

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

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

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

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

    复制代码
     <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>
    复制代码


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

    复制代码
    <?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> 
    复制代码

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

     

    同时可以修正ua获取问题:

    when use UrlMkGetSessionOption to acquire IE default UserAgent, I get the string "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)".But my IE Browsertype is IE11 and not in the compatible mode.

    You are probably testing on a Webbrowser and your feature control keys are not set so it is setting ie7 as default browser. Check this key and change the value to "11001" for IE11:

    -HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
       SOFTWARE
          Microsoft
             Internet Explorer
                Main
                   FeatureControl
                      FEATURE_BROWSER_EMULATION
                         yourApplication.exe = (DWORD) 00009000
    

    https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation

    Note: if your os is 64 bits and your app is 32 bits, you have to take this path instead: SOFTWARE/WOW6432NODE/MICROSOFT...

    参考IE开发文档:

    https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms775114(v=vs.85)

  • 相关阅读:
    利用合成数据进行时间序列分类的数据扩充方法
    基于 KubeSphere CI/CD 将 Spring Boot 项目发布至 Kubernetes
    矩阵白化
    delphi 过滤开头 结尾 全部 空格的函数
    delphi CopyFileProgressBar 拷贝文件显示进度条
    delphi 分享三个随机字符串
    delphi IsIPAdress 非正则表达式验证IP的方法
    delphi PosAnsi
    delphi公用函数
    Delphi中break,exit,abort跳出循环的比较
  • 原文地址:https://www.cnblogs.com/bigben0123/p/14333977.html
Copyright © 2011-2022 走看看