Delphi編譯的程序如何獲取管理員權限


1.制作manifest文件

 1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 2 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
 3 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
 4 <security>
 5 <requestedPrivileges>
 6 <requestedExecutionLevel level="requireAdministrator" uiAccess="false">
 7 </requestedExecutionLevel>
 8 </requestedPrivileges>
 9 </security>
10 </trustInfo>
11 <dependency>
12 <dependentAssembly>
13 <assemblyIdentity type="win32"
14 name="Microsoft.Windows.Common-Controls"
15 version="6.0.0.0"
16 processorArchitecture="x86"
17 publicKeyToken="6595b64144ccf1df"
18 language="*">
19 </assemblyIdentity>
20 </dependentAssembly>
21 </dependency>
22 </assembly>

用記事本保存為:UAC.manifest

2.第二步對於D7和XE系列有差異。

(1)XE系列

 

如上圖所示,選擇 Use custom manifest,然后選擇剛剛保存的文件。

這里最好選擇All configurations,這樣無論是調試模式還是release都支持了。

然后編譯工程,輸出exe文件。可以看到小盾牌了。

運行程序,會彈出提權確認框:

 

(2)Delphi 7

D7里面是沒有這個設置的,可以通過資源文件來實現。

a.新建一個文件文件,輸入內容如下:

1 24 "UAC.manifest"

1-代表資源編號

24-資源類型為RTMAINIFEST

將文件保存為:uac.rc

b.將RC文件編譯為資源文件

brcc32 uac.rc 

得到uac.RES 文件,注意uac.rc的路徑。

c.修改工程文件(DPR)

在{$R *.RES}后面追加

{$R 'uac.RES'}

d.編譯工程文件,得到EXE文件

小盾牌看見了吧?

運行EXE

提權確認框也彈出來了。



免責聲明!

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



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