2010-06-04 49 views
1

我的安裝程序部署了一個配置exe,用於在同樣安裝的windows服務上進行一些基本配置。該exe還需要創建和編寫一些註冊表項。在Windows Server 2008環境中,這些密鑰無法創建。我調查了一下,發現這是一個管理員權限,並且EXE沒有提示在2008年UAC下需要的管理員權限。我可以通過右鍵單擊exe並以管理員身份運行來解決此問題。這不是理想的,因爲它是我需要通知我們的客戶表演的額外步驟。在運行該exe文件時是否有其他提升管理權限的方式?Win Server 2008上的UAC讓我頭疼!

回答

1

將清單放在exe文件上。我可以告訴你如何使用Visual Studio嵌入清單,如果你讓我知道你使用的是什麼版本。如果你沒有使用Visual Studio,或者你沒有構建exe文件,那麼你可以將清單文件放在與exe相同的文件夾中,這也可以工作。在這種情況下,文件的名稱必須與您的exe相同,最後使用.manifest,例如foo.exe是foo.exe.manifest。內容應該是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> 
    <security> 
     <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> 
     <!-- UAC Manifest Options 
      If you want to change the Windows User Account Control level replace the 
      requestedExecutionLevel node with one of the following. 

     <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
     <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> 

      If you want to utilize File and Registry Virtualization for backward 
      compatibility then delete the requestedExecutionLevel node. 
     --> 
     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
     </requestedPrivileges> 
    </security> 
    </trustInfo> 
</asmv1:assembly> 

通告requestedExecutionLevel可能的值都在這裏評論,而這一次使用requireAdministrator。現在它會一直提升,因此爲你工作。

+0

謝謝凱特。我一直在嘗試,但目前仍然遇到同樣的問題。你可以建議告訴我如何在EXE中嵌入清單,我使用的是visual studio 2008.(它沒有從我的外部清單文件中看到它的外觀,我恰當地重命名了assemblyIdentity名稱和版本屬性也fyi) – user48408 2010-06-04 12:22:01

+0

一個exe不稱爲foo.config。要麼你沒有顯示擴展名,所以它是真的foo.config.exe,或者exe讀取配置文件,你需要找出exe的名稱。 在Visual Studio 2008中,對於C#:嚮應用程序清單添加一個項目。編輯它,以便您請求requireAdministrator(您可以從評論複製。)然後右鍵單擊該項目並選擇屬性。在應用程序選項卡下拉清單並選擇app.manifest。建立。 對於VB,只需轉到項目屬性的「應用程序」選項卡,單擊UAC設置,更改清單並構建。 – 2010-06-04 12:36:36

+0

並在此元素中: '不管你提供什麼名字。我通常會改變它,但似乎對UAC沒有影響。 – 2010-06-04 12:37:45