views:

173

answers:

2

I want to start a windows service which I have created from another windows service. I am using the service Controller which is available. But when I try to start the service I get a message, "Cannot open MyTestService service on computer '.'"

I am working on the windows xp operating system. I have given the Account for the service which I am trying to start as LocalSystem and I also tried with Localservice account.

Do I need to give special permissions to the windows service, to be able to started by another service.

A: 

Does it explain the reason? A service won't be marked as running if it immediately returns from the 'Start ()' call (i.e. it's finished). What does your service code look like, basically? Can you start the service through services.msc?

Noon Silk
Yes, I am able to start the service from the services.msc. I am trying to start the service in the timer elapsed event as given belowprivate void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (serviceController1.Status == ServiceControllerStatus.Stopped) { serviceController1.Start(); timer1.Stop(); } }
AvidProgrammer
Are you using the right name? Go to properties on the service and make sure you're using the 'Service name' field ... (I just tested starting one with the ServiceController; and it works fine. If it's not the name, it's permissions).
Noon Silk
Unless your service requires some startup parameters.
Noon Silk
Do I need to give special permissions to the windows service, to be able to started by another service
AvidProgrammer
I checked the name. I have given the display name of the service. It is automatically popped in the services list to be selected.
AvidProgrammer
I'm not entirely sure about permissions to be honest; my guess is that you'd need at least the permissions of the service itself. But I don't know, so I can't help on that, sorry.
Noon Silk
Try looking in the event log? When a service fails to start there is usually some indication of why in there. (Not sure if this is the same if you are using ServiceController, but still, worth a look) :)
Matt
+2  A: 

Have you also considered to establish dependencies between your Windows Services. This way when your server reboots Windows will order all services according to their dependencies.

Here are a couple useful links:

Philippe Monnet