簡體   English   中英

C# - Windows服務安裝程序沒有注冊服務

[英]C# - windows service installer not registering service

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

這是我到目前為止所做的:

服務類名稱是默認值 - Service1。

在項目安裝程序中,服務安裝程序的ServiceName與類名稱 - Service1匹配。

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

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

有任何想法嗎?

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

[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);
    }
}

確保您已在服務項目中創建了ServiceInstaller和ServiceProcessInstaller類。 (查看此鏈接了解更多信息)。

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

如果這不起作用,請重新啟動計算機。 您可能鎖定了一些文件。

不言而喻,您可能需要在計算機上擁有管理權限才能使其正常工作。

我想我已經明白了。 它可能是Designer代碼的錯誤,或者我錯過了一步。

我認為在設計器代碼中,在InitializeComponent()方法中,它應該添加:

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

它不存在,所以我在ProjectInstaller構造函數中添加了它:

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

現在安裝時,它被列為計算機管理中的一項服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM