当前位置:首页 > Windows程序 > 正文

通过修改manifest文件来解决Vista/Win7/Win8下应用程序兼容性问题

2021-05-25 Windows程序

标签:

        在Vista/Win7/Win8下,有一个系统兼容性助手功能,在安装程序安装完成或卸载完成后,可能会弹出应用程序兼容性助手相关的提示,提示程序可能安装不正确,很是烦人。如下图所示:

技术分享


事实上,,我们的程序兼容性是没问题的,只不过是在程序中没有指定应用程序兼容的操作系统,所以导致了这些问题。

        VS2008和VS2010可以生成一个与exe应用程序相关联的.manifest文件,微软已经为该文件中添加了一个新的<compatibility> 字段, 这个字段用来指定你的应用程序可以兼容的操作系统,进而可以解决程序兼容性问题。

        .menifest文件是一个随工程编译产生的xml文件,作用是为操作系统提供了对应用程序部分信息的描述,每个exe程序或者dll都必须有一个manifest,对于应用程序而言,可以是一个和exe文件同一目录下的.manifest文件,也可以是作为一个资源嵌入在exe文件内部的(通过修改项目配置manifest tool->input output->Embed Manifest->yes), 如果应用程序没有.manifest文件,则会提示丢失MSVCR90D.dll,无法运行。

以下是添加了<compatibility> 字段的manifest文件,添加了对Vista/Win7/Win8系统的兼容性的支持:

[html] view plain

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>    

  <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">    

      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">    

          <application>    

              <!--The ID below indicates application support for Windows Vista -->    

              <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>   

              <!--The ID below indicates application support for Windows 7 -->    

              <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>   

              <!--The ID below indicates application support for Windows 8 -->    

              <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>  

          </application>    

     </compatibility>    

   </assembly>   


        如果你的项目会生成一个.manifest文件的话,也就是不是内嵌模式,直接修改该文件,重新编译即可。如果你的项目设置的是将.manifest文件内嵌到应用程序内部,则你需要先修改为非内嵌模式,编译,生成.manifest文件,修改该文件后,再将工程属性改为内嵌模式。同时将修改后的.manifest文件通过additional manifest file 选项添加到工程里面,重新编译即可。(好像直接编写一个上述内容的.manifest文件,文件名:exe名称.exe.manifest,然后将清单设置为内嵌模式,直接将manifest文件添加到工程中编译即可)

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70698.html