2012-03-05 57 views
6

我有一個Windows服務應該在安裝期間由用戶指定的域帳戶下運行。讓用戶指定服務在哪個帳戶上運行

安裝程序Wix的這種可能性(即向用戶詢問服務應該使用的帳戶+密碼)?

背景

我的服務需要訪問網絡共享和LocalSystem沒有適當的權限,所以我想用現有的域用戶帳戶。

回答

7

ServiceInstall元素是你的朋友在這裏。它包含屬性Account和Password。 所以,作者一對夫婦的控制你的對話框上:

<Control Type="Edit" Property="ACCOUNT" ... /> 
<Control Type="Edit" Property="PASSWORD" Password="Yes" ... /> 

,並使用這些屬性來指示ServiceInstall:

<ServiceInstall Id="..." Account="[ACCOUNT]" Password="[PASSWORD]" Type="ownProcess" ... /> 

希望這有助於。

+0

我想我明白你的意思:我有我自己的自定義對話框添加到要求輸入賬號+密碼的用戶安裝。我可以在'ServiceInstall'元素中使用這些值來設置一個帳戶。正確?沒有可以使用的標準,現成的對話框? – nabulke 2012-03-05 15:10:33

+0

正確。不,沒有標準的對話框,據我所知,但創建它應該很簡單 – 2012-03-05 15:21:01

+0

感謝您的幫助。 – nabulke 2012-03-05 15:36:31

3

您需要同時擁有要運行服務的用戶的帳戶名和密碼。我可以通過向我的安裝程序添加一個自定義用戶界面來請求用戶名和密碼,然後使用ServiceInsall元素上的帳戶和密碼屬性提供的值完成此操作。

請注意,用於運行服務的帳戶必須具有「登錄身份」服務特權。默認情況下,這不會授予用戶。我能夠使用UtilExtension架構中的用戶元素將此priveledge添加到用戶。如果運行安裝程序的用戶是管理員,則僅向用戶添加特權纔會成功。

這是我使用的代碼。 SERVICECREDENTIALS_USERLOGIN和SERVICECREDENTIALS_PASSWORD是從自定義用戶界面填充的屬性。

<Component Id="ServiceEXE" Guid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"> 
    <File Id="ServiceEXE" Name="YourService.exe" DiskId="1" 
     Source="path\to\YourService.exe" KeyPath="yes" /> 
    <util:User Id="UpdateUserLogonAsService" UpdateIfExists="yes" CreateUser="no" Name="[SERVICECREDENTIALS_USERLOGIN]" 
      LogonAsService="yes" /> 
    <ServiceInstall Id="ServiceInstall" Type="ownProcess" Vital="yes" Name="YourService" 
        DisplayName="Your Service" Description="Your Service description" 
        Start="auto" Account=".\[SERVICECREDENTIALS_USERLOGIN]" Password="[SERVICECREDENTIALS_PASSWORD]" 
        ErrorControl="normal" Interactive="no" /> 

    <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="YourService" Wait="yes" /> 
</Component> 

瞭解更多信息: http://skullpsgblog.blogspot.in/2015/11/in-wix-setting-services-user-account.html

相關問題