如何讓Delphi程序啓動自動「以管理員身份運行"

因爲Vista之後win中加入的UAC安全機制,採用Delphi開發的程序若是不右鍵點擊「以管理員身份運行」,則會報錯。
   在XE2以上的Delphi版本處理這個問題已經很是簡單了。
   右建點擊工程,選擇「Options」->「Applicaion」下,將Runtime themes項設置爲「Use Custom manifest」,點擊下方按鈕,選擇相應的Manifest文件便可。
   須要注意的是:Debug和Release模式不一樣,要進行一樣設置
   至於Manifest文件,也就是一個XML文檔,原文以下:
<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>
XE2之前的版本解決辦法,將上面的xml內容保存爲UAC.manifest
 而後編輯一個RC文件,名稱爲uac.rc 以下所示:
1 24 UAC.manifest
其中: 
1-表明資源編號 
24-資源類型爲RTMAINIFEST 
UAC.manifest-前面的文件名稱

用brcc32編譯這個rc文件爲res文件,以下所示:html

brcc32 uac.rc -fouac.res

在程序裏面加入安全

{$R uac.res}
讓Delphi編譯的時候,把uac.res編譯進exe文件
  把文件放到vista或win7下運行,就會看程序圖標下面顯示UAC盾牌標誌了。

內容整合於網絡:網絡

http://www.bubuko.com/infodetail-784679.html
http://www.cnblogs.com/mumble/p/3382305.htmlui

相關文章
相關標籤/搜索