11

我正在尝试使用 Windows 服务的安装程序,并希望避免使用 InstallUtil.exe。安装程序似乎工作正常(可执行文件和 dll 位于正确的目录中),但该服务未出现在计算机管理下。

这是我到目前为止所做的:

服务类名称是默认值 - Service1。

在项目安装程序中,服务安装程序的 ServiceName 与类名 - Service1 匹配。

在自定义操作下,服务的主要输出被添加到安装、提交、回滚和卸载。

我使用http://support.microsoft.com/kb/816169作为参考。

有任何想法吗?

4

3 回答 3

16

您的服务项目是否有安装程序类?你应该有一个看起来像这样的:

[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);
    }
}
于 2009-07-27T21:13:09.433 回答
3

Make sure you've created a ServiceInstaller and ServiceProcessInstaller class in your service project. (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.

于 2009-07-27T20:06:42.627 回答
0

我想我已经想通了。这可能是 Designer 代码的错误,或者我错过了一个步骤。

我认为在设计器代码中,在 InitializeComponent() 方法中,应该添加:

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

它不存在,所以我在 ProjectInstaller 构造函数中添加了这个:

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

现在在安装时,它被列为计算机管理中的一项服务。

于 2009-07-27T21:06:12.507 回答