sreeni

sreeni

  • NA
  • 3
  • 0

Cannot start service on machine ‘.’

Jul 29 2005 2:51 PM

I have created two services X1 and X2.  Stop and start operations of Service X2 should controlled by X1. I have written the below code.

System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("X2");

                                                // check the current state of X2 service, either manually started by any one

 

                                                if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running))

                                                {

                                                            sc.Stop();

                                                            sc.Start();

 

                                                }

                                                else

                                                {

                                                            sc.Start();

                                                }

                                                            //Stop X2 service

                                               

                                                            sc.Stop();

 

Both services are running with the same ID & Password and on the same machine.

I am getting the below error message ‘Cannot start X2 service on machine ‘.’’. Some times it will start the service and will get an error message ‘Cannot stop X2 service on machine ‘.’’. Please let me know what the problem in my code or permissions are?

Thanks in advance.


Answers (1)