2009-07-27 172 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); 

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