Delphi XE2之前的版本實作比較麻煩,步驟如下:
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盾牌标志了。
Delphi XE2之後的版本(包含Delphi XE2)就簡單多了,步驟如下:
一 首先編輯一個檔案,内容如下:
<?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)才能正常運作。
二
右建點選工程,選擇“Options”->“Applicaion”下,将Runtime themes項設定為“Use Custom manifest”,點選下方按鈕,選擇第一步中建立的Manifest檔案即可。
需要注意的是:Debug和Release模式不同,要進行同樣設定
如圖:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZwpmLzUzM0YTMzYDNxIDMzEDMy8CXyAzMxAjMvwVZslmRwV1Lc12bj5CcvRXaoBHblRmL3d3dvw1LcpDc0RHaiojIsJye.jpg)