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

Dav*_*son 10 c# windows-installer windows-services setup-deployment

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

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

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

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

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

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

有任何想法吗?

Has*_*niH 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);
    }
}
Run Code Online (Sandbox Code Playgroud)