給你的程序在Win7上加個小盾,設置manifest

用vs2005以上版本的編譯時候可以直接設置信任權限爲Administrator.

設置方法如下:

工程選項->Linker->Manifest File->UAC Execution Level  選擇requireAdministrator即可

但是在VC 6.0 和VS2003編譯程序時沒有此選項,需要自己添加

1. 把以下類似代碼加入記事本並以工程名.exe.manifest命名

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
<assemblyIdentity 
    version="1.0.0.0" 
    processorArchitecture="X86" 
    name="Microsoft.Windows.Sports"
    type="win32" 
/> 
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>


2. Project->Add Existing Item...將工程名.exe.manifest添加到工程中。
工程名.exe.manifest這個文件一定要放在工程目錄文件夾下res文件夾裏面。

3. 打開工程中的Resource.h文件,加上:
#define IDR_MANIFEST  1
#define RT_MANIFEST   24


4. 將工程的res\*.rc2文件打開, 加上:
// Add manually edited resources here...
IDR_MANIFEST RT_MANIFEST MOVEABLE PURE  "res\\工程名.exe.manifest"


5. Rebuild.....就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章