Windows服务安装问题

Fur*_*ala 11 windows installation service visual-studio-2008-sp1 c#-3.0

当我开始使用installutil进行安装时,它给出了以下错误,我已经设置了ServiceInstaller和ServiceInstallerProcess

System.InvalidOperationException:由于缺少ServiceProcessInstaller,安装失败.ServiceProcessInstaller必须是包含的安装程序,或者必须与ServiceInstaller在同一安装程序上的Installers集合中出现.

等待你宝贵的想法.

感谢您

小智 23

我在安装程序中遇到了同样的问题,发现在InitializeComponent()方法的[YourInstallerClassName] .Designer.cs中,dfault生成的代码是Missing添加ServiceProcessInstaller

        // 
        // [YourInstallerClassName]
        // 
        this.Installers.AddRange(new System.Configuration.Install.Installer[] {
        this.serviceInstaller1});
Run Code Online (Sandbox Code Playgroud)

只需在我的案例中添加您的ServiceProcessInstaller:

        // 
        // ProjectInstaller
        // 
        this.Installers.AddRange(new System.Configuration.Install.Installer[] {
        this.serviceProcessInstaller1,   //--> Missing
        this.serviceInstaller1});
Run Code Online (Sandbox Code Playgroud)

并且安装项目有效.

  • @FMFF,对于有兴趣通过UI进行操作的任何人,只需确保Installer项目上的serviceInstaller和serviceProcessInstallers都将其父级作为ProjectInstaller。 (2认同)

Tom*_*ski 1

通常,这意味着您未能使用 RunInstaller(true) 来指定安装程序。这是我手边有一个有效的示例:

namespace OnpointConnect.WindowsService
{
    [RunInstaller(true)]
    public partial class OnpointConnectServiceInstaller : Installer
    {
        private ServiceProcessInstaller processInstaller;
        private ServiceInstaller serviceInstaller;

        public OnpointConnectServiceInstaller()
        {
            InitializeComponent();
        }

        public override string HelpText
        {
            get
            {
                return
                    "/name=[service name]\nThe name to give the OnpointConnect Service.  " +
                    "The default is OnpointConnect.  Note that each instance of the service should be installed from a unique directory with its own config file and database.";
            }
        }

        public override void Install(IDictionary stateSaver)
        {
            Initialize();
            base.Install(stateSaver);
        }

        public override void Uninstall(IDictionary stateSaver)
        {
            Initialize();
            base.Uninstall(stateSaver);
        }

        private void Initialize()
        {
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();
            processInstaller.Account = ServiceAccount.LocalSystem;
            serviceInstaller.StartType = ServiceStartMode.Manual;

            string serviceName = "OnpointConnect";
            if (Context.Parameters["name"] != null)
            {
                serviceName = Context.Parameters["name"];
            }
            Context.LogMessage("The service name = " + serviceName);

            serviceInstaller.ServiceName = serviceName;

            try
            {
                //stash the service name in a file for later use in the service
                var writer = new StreamWriter("ServiceName.dat");
                try
                {
                    writer.WriteLine(serviceName);
                }
                finally
                {
                    writer.Close();
                }

                Installers.Add(serviceInstaller);
                Installers.Add(processInstaller);
            }
            catch (Exception err)
            {
                Context.LogMessage("An error occured while creating configuration information for the service.  The error is "
                                   + err.Message);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)