Delphi下如何使程式在Win7/Vista上用管理員權限運行

來源:互聯網
上載者:User
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

四 、在程式program檔案{$R *.res}後面加入
{$R uac.res}

同時去掉Project ->Options->Application->Enable runTime themes 的“√”,然後重新編譯exe檔案即可

五 、把檔案放到vista或win7下運行,就會看程式表徵圖下面顯示UAC盾牌標誌了。

一、 首先編輯一個檔案,內容如下:
<?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

四 、在程式program檔案{$R *.res}後面加入
{$R uac.res}

同時去掉Project ->Options->Application->Enable runTime themes 的“√”,然後重新編譯exe檔案即可

五 、把檔案放到vista或win7下運行,就會看程式表徵圖下面顯示UAC盾牌標誌了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.