2009-07-27 114 views
9

我正在嘗試使用Windows服務的安裝程序,並且希望避免使用InstallUtil.exe。安裝程序似乎正常工作(可執行文件和dll位於正確的目錄中),但該服務未顯示在「計算機管理」下。C# - Windows服務安裝程序未註冊服務

這是我到目前爲止已經完成:

服務類名是默認 - 服務1。

在Project安裝程序中,服務安裝程序的ServiceName與類名稱Service1相匹配。

在自定義操作下,該服務的主要輸出已添加到安裝,提交,回滾和卸載。

我使用http://support.microsoft.com/kb/816169作爲參考。

任何想法?

回答

15

您的服務項目是否有安裝程序類?你應該有一個看起來像這樣的:

[RunInstaller(true)] 
public partial class Service1Installer : Installer 
{ 
    public Service1Installer() 
    { 
     InitializeComponent(); 
     ServiceProcessInstaller process = new ServiceProcessInstaller(); 
     process.Account = ServiceAccount.LocalSystem; 

     ServiceInstaller serviceAdmin = new ServiceInstaller(); 
     serviceAdmin.StartType = ServiceStartMode.Manual; 
     serviceAdmin.ServiceName = "Service1"; 
     serviceAdmin.DisplayName = "Service1"; 
     serviceAdmin.Description = "Service1"; 

     Installers.Add(serviceAdmin); 
    } 
} 
+0

這就是我錯過的。我認爲Installers.Add()部分將包含在自動生成的設計器代碼中,但事實並非如此。也許他們改變了它? – 2009-07-27 21:21:46

3

確保您已在服務項目中創建ServiceInstaller和ServiceProcessInstaller類。 (有關更多信息,請參閱this link)。

關閉計算機管理和服務窗口,再次運行安裝程序,然後重新打開「服務」窗口。

如果這樣不起作用,請重新啓動計算機。你可能會鎖定一些文件。

不言而喻,您可能需要機器的管理權限才能正常工作。

+0

在發佈的鏈接中的示例代碼讓我在正確的軌道,謝謝一堆。 – 2009-07-27 21:07:00

0

我想我已經想通了。這可能是設計器代碼的錯誤,或者我錯過了一個步驟。

我覺得在設計器代碼,在InitializeComponent()方法,它應該補充:

this.Installers.AddRange(new System.Configuration.Install.Installer[] {this.serviceProcessInstaller1, this.serviceInstaller1}); 

這是不存在的,所以我說這在ProjectInstaller構造:

Installers.Add(serviceInstaller1); 
Installers.Add(serviceProcessInstaller1); 

現在安裝時,它在計算機管理中列爲服務。