2015-04-02 95 views
0

我希望安裝程序(在安裝過程中)提示用戶輸入憑據。我真的希望它提示用戶。 我已經完成了我在這裏閱讀的大多數問題/答案中看到的,將該帳戶設置爲用戶。c#windows服務安裝程序提示用戶輸入憑據

我也試圖用最低限度的方式來做到這一點。 我創建了一個新的Windows服務項目。然後我創建了一個Visual Studio安裝程序(安裝項目)。

在windows服務項目的.cs文件(我稱之爲ProjectInstaller)中,右鍵單擊主設計頁面並單擊添加安裝程序,出現兩個安裝程序。在我ProjectInstaller.Designer.cs,我加在InitializeComponent方法這行代碼

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User; 

然後我去了我的安裝程序安裝項目,右鍵單擊,設置主要輸出到Windows服務項目,就是這樣。編譯所有內容並運行安裝程序文件,但它沒有提示我輸入憑據。

我不知道這是否會幫助,但是這是整個InitializeComponent方法

private void InitializeComponent() 
    { 
     this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller(); 
     this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller(); 
     this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User; 
     // 
     // serviceProcessInstaller1 
     // 
     this.serviceProcessInstaller1.Password = null; 
     this.serviceProcessInstaller1.Username = null; 
     this.serviceProcessInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceProcessInstaller1_AfterInstall); 
     // 
     // serviceInstaller1 
     // 
     this.serviceInstaller1.ServiceName = "Service1"; 
     this.serviceInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller1_AfterInstall); 
     // 
     // ProjectInstaller 
     // 
     this.Installers.AddRange(new System.Configuration.Install.Installer[] { 
     this.serviceProcessInstaller1, 
     this.serviceInstaller1}); 

    } 

我缺少的是讓自己的安裝程序會提示用戶輸入憑據?

回答

1

默認情況下你不能這樣做。 可以通過新的自定義頁面創建一個WiX設置,讓用戶輸入服務帳戶的憑證。

+0

你能否解釋我們爲什麼默認不能這樣做?視覺工作室的版本是否重要?我在visual studio 2013上運行 – ANiceSunset 2015-04-02 17:48:17

+1

因爲提示憑據不是服務安裝程序的功能。 – 2015-04-02 18:33:26

相關問題