windows從Vista起引入了UAC控制,對應用程式的一些行為做出了限制,例如修改系統資料庫的操作,如果程式沒有申請到管理者權限就無法執行該操作。如何讓delphi開發的程式可以支援在啟動時就申請管理者權限呢,可以參考這篇博文http://tech.ddvip.com/2009-04/1239359402114436.html
需要特别說明的是如果使用Delphi2010開發,IDE會自動為項目添加一個資源檔案,在這個資源檔案中就有UAC控制節,資源檔案的名稱與項目名稱相同,檔案的内容如下:
UAC資源檔案 <? xml version="1.0" encoding="UTF-8" standalone="yes" ?>
< assembly xmlns ="urn:schemas-microsoft-com:asm.v1" manifestVersion ="1.0" >
< assemblyIdentity
type ="win32"
name ="CodeGear RAD Studio"
version ="14.0.3615.26342"
processorArchitecture ="*" />
< dependency >
< dependentAssembly >
< assemblyIdentity
type ="win32"
name ="Microsoft.Windows.Common-Controls"
version ="6.0.0.0"
publicKeyToken ="6595b64144ccf1df"
language ="*"
processorArchitecture ="*" />
</ dependentAssembly >
</ dependency >
< trustInfo xmlns ="urn:schemas-microsoft-com:asm.v3" >
< security >
< requestedPrivileges >
< requestedExecutionLevel
level ="asInvoker"
uiAccess ="false" />
</ requestedPrivileges >
</ security >
</ trustInfo >
</ assembly >
可以看到預設的權限級别是 level="asInvoker" 因為這個檔案的存在,會導緻按照上述博文編譯好的MANIFEST資源失效,最簡單的解決辦法,把IED自動生成的與項目同名的資源檔案删除即可。
在這裡提供一個已經制作好的包含MANIFEST的資源檔案下載下傳。
Mainfest資源檔案uac.res下載下傳
轉載于:https://www.cnblogs.com/endlock/archive/2010/06/01/1748883.html