【问题标题】:How to Resolve error 1001 while installing windows service安装windows服务时如何解决错误1001
【发布时间】:2011-10-04 12:31:00
【问题描述】:

安装 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(@"root\CIMV2", 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();

    }

【问题讨论】:

    标签: c# .net windows-services setup-project


    【解决方案1】:

    你不应该发现错误然后忽略它。

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

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

    【讨论】:

    • 尊敬的用户感谢您的回答,但我也试过这样:catch(System.Security.SecurityException exc) { MessageBox.Show("OnStart :"+exc.ToString()); }
    • 我认为 MessageBox 不能在 Windows 服务中工作。调用 MessageBox.Show() 可能会导致另一个错误。您需要将原始错误记录到文本文件或 Windows 事件日志或类似文件中。
    • @MubbasherKhaliq 在服务中如果你想在屏幕上写一些东西是不可能的但是你可以把它记录到一个文本文件或一个 Windows 日志条目中,这很容易做到,它会给你找出服务中出了什么问题的更好起点。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 2013-05-16
      • 1970-01-01
      • 2020-09-01
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多