一句话Windows

本文主要记录windows开发中遇到的一句话技巧和知识点。


为VC++ 2008添加application compatibility段

使用visual studio为应用程序添加manifest方法很简单,下面为常用的一个manifest文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestversion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
    <trustinfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedprivileges>
                <requestedexecutionlevel level="asInvoker" uiaccess="false">
                </requestedexecutionlevel>
            </requestedprivileges>
        </security>
    </trustinfo>
    <dependency>
        <dependentassembly>
            <assemblyidentity name="Microsoft.VC90.CRT" processorarchitecture="x86" publickeytoken="1fc8b3b9a1e18e3b" type="win32" version="9.0.21022.8">
            </assemblyidentity>
        </dependentassembly>
    </dependency>
    <dependency>
        <dependentassembly>
            <assemblyidentity language="*" name="Microsoft.Windows.Common-Controls" processorarchitecture="x86" publickeytoken="6595b64144ccf1df" type="win32" version="6.0.0.0">
            </assemblyidentity>
        </dependentassembly>
    </dependency>
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
            <!-- Windows 10 -->
            <supportedos id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}">
            </supportedos>
            <!-- Windows 8.1 -->
            <supportedos id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}">
            </supportedos>
            <!-- Windows Vista -->
            <supportedos id="{e2011457-1546-43c5-a5fe-008deee3d3f0}">
            </supportedos>
            <!-- Windows 7 -->
            <supportedos id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}">
            </supportedos>
            <!-- Windows 8 -->
            <supportedos id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}">
            </supportedos>
        </application>
    </compatibility>
</assembly>

但是由于visual Studio2008不支持compatibility字段,直接这样添加会报错,所以需要先正常生成文件,然后再使用新版的mt.exe手动嵌入manifest文件。

使用mt.exe为程序添加manifest文件的命令很简单: mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -outputresource:"r:\shared\hl33m.exe;#1"

参考页面