如何解决安装windows服务时出现的1001错误



安装windows服务时出现以下错误

错误1001。在安装的提交阶段发生异常。此异常将被忽略,并继续安装。但是,安装完成后,应用程序可能无法正常运行->无法在计算机'.'上启动服务ACSERVICE2。-->服务没有及时响应启动或控制请求。

任何帮助都是感激的…

代码为:

    protected override void OnStart(string[] args)
    {
        try
        {
            AC_Main objMain = new AC_Main();
            td=new Thread(new ThreadStart(objMain.Main));
            td.IsBackground = true;
            td.Start();
            eLog.WriteEntry("Service Started at :" + System.DateTime.Now.ToString());
        }
        catch(System.Security.SecurityException exc)
        {
        }
    }

 protected override void OnStop()
        {
            td.Abort();
            eLog.WriteEntry("Service Stopped at :" + System.DateTime.Now.ToString());
        }

提交方法是:

private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
    {
        serviceController.ServiceName = "ACSERVICE2";
        ConnectionOptions coOptions = new ConnectionOptions();
        coOptions.Impersonation = ImpersonationLevel.Impersonate;
        ManagementScope mgmtScope = new System.Management.ManagementScope(@"rootCIMV2", coOptions);
        mgmtScope.Connect();
        ManagementObject wmiService;
        wmiService = new ManagementObject("Win32_Service.Name='" + this.serviceController.ServiceName + "'");
        ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
        InParam["DesktopInteract"] = true;
        ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
        this.serviceController.Start();
    }

永远不要捕获错误然后忽略它。

那可能是你的问题。如果在catch块中添加一些日志记录,会发生什么情况?

catch(System.Security.SecurityException exc)
{
    eLog.WriteEntry("SecurityException: " + exc.Message);
}

是的,如果您没有正确卸载要重新安装的服务,就会发生这种情况。几天前我也遇到过同样的问题。我创建了一个新项目,复制了相同的代码,并从头开始安装服务。我的问题是

最新更新