Delphi下如何使程序在Win7/Vista上用管理員權限運行(轉)


Delphi程序必須在資源里面嵌入MANIFEST信息
 一 首先編輯一個文件,內容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator"/>
      </requestedPrivileges>
    </security>
</trustInfo>
</assembly>
保存為UAC.manifest,這里文件是隨意的。特別注意紅色的“requireAdministrator”,這個表示程序需要管理員(Administrator)才能正常運行。

二 然后編輯一個RC文件,名稱為uac.rc 如下所示:
1 24 UAC.manifest
其中:
1-代表資源編號
24-資源類型為RTMAINIFEST
UAC.manifest-前面的文件名稱

三 用brcc32編譯這個rc文件為res文件,如下所示:
brcc32 uac.rc -fouac.res

四 在程序里面加入
{$R uac.res}
讓Delphi編譯的時候,把uac.res編譯進exe文件

五 把文件放到vista或win7下運行,就會看程序圖標下面顯示UAC盾牌標志了。

from:http://blog.chinaunix.net/uid-20718335-id-364391.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM