开发者

How to Resolve error 1001 while installing windows service

I am getting following error while installing windows service.

Error 1001 . An Exception occurred during the commit phase of the installation. This exception will be ignored and installation will continue. However , the application might not function correctly after installation is complete --> Cannot start service ACSERVICE2 on Computer'.'.-->The service did not respond to the start or control request in a timely fashion.

Any help is appreciated...

Code is :

    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());
        }

Committed Method is :

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();

    }


You should never catch an error and then ignore it.

That might be your problem. What happens if you add some logging to the catch block, something like this?

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


Yes, this happens if you didn't correctly uninstall the service you are trying to install again. I had the same problem a few days ago. I created new project, copied the same code and installed the service again from scratch. My problem was that

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜