简体   繁体   English

C# - Windows服务安装程序没有注册服务

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

I'm trying to use an installer for a Windows service, and would like to avoid using InstallUtil.exe. 我正在尝试使用Windows服务的安装程序,并希望避免使用InstallUtil.exe。 The installer appears to work correctly (the executable and dlls are in the correct directory), but the service doesn't appear under Computer Management. 安装程序似乎正常工作(可执行文件和dll位于正确的目录中),但该服务未显示在“计算机管理”下。

Here's what I've done so far: 这是我到目前为止所做的:

The service class name is the default - Service1. 服务类名称是默认值 - Service1。

In the Project installer, the ServiceName of the service installer matches the class name - Service1. 在项目安装程序中,服务安装程序的ServiceName与类名称 - Service1匹配。

Under the Custom Actions, the primary output of the service was added to Install, Commit, Rollback, and Uninstall. 在“自定义操作”下,服务的主要输出已添加到“安装”,“提交”,“回滚”和“卸载”。

I'm using http://support.microsoft.com/kb/816169 as a reference. 我使用http://support.microsoft.com/kb/816169作为参考。

Any ideas? 有任何想法吗?

Does your service project have an Installer class? 您的服务项目是否具有安装程序类? You should have one that looks something like this: 你应该有一个看起来像这样的:

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

Make sure you've created a ServiceInstaller and ServiceProcessInstaller class in your service project. 确保您已在服务项目中创建了ServiceInstaller和ServiceProcessInstaller类。 (Check this link for more info). (查看此链接了解更多信息)。

Close computer management and the Services window, run your installer again, and reopen the Services window. 关闭计算机管理和“服务”窗口,再次运行安装程序,然后重新打开“服务”窗口。

If that doesn't work, restart your computer. 如果这不起作用,请重新启动计算机。 You might have some files locked. 您可能锁定了一些文件。

It goes without saying that you probably need administrative privileges on the machine for this to work properly. 不言而喻,您可能需要在计算机上拥有管理权限才能使其正常工作。

I think I've figured it out. 我想我已经明白了。 It might be a bug with the Designer code, or perhaps I missed a step. 它可能是Designer代码的错误,或者我错过了一步。

I think in the designer code, in the InitializeComponent() method, it's supposed to add: 我认为在设计器代码中,在InitializeComponent()方法中,它应该添加:

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

It wasn't there, so I added this in the ProjectInstaller constructor: 它不存在,所以我在ProjectInstaller构造函数中添加了它:

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

Now on installation, it's listed as a service in Computer Management. 现在安装时,它被列为计算机管理中的一项服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM