Getting System.ServiceProcess.ServiceController.ExecuteCommand(int) to work

T

Tom J

What do I have to do to get
System.ServiceProcess.ServiceController.ExecuteCommand(int) to work?

I have written a service that overrides OnCustomCommand to handle commands
sent to it.

If I have application code like:

----------------------------------------------------------
ServiceController sc = new ServiceController("MyService");

sc.Start(); // this works

...code that checks running state is here...

sc.ExecuteCommand(1); //throws the exception

---------------------------------------------------------

I get an exception of: Cannot control MyService service on computer "."

Are there specific things i have to do to the service to allow it to accept
commands other than the standard start, stop, etc?

Thanks in Advance....Tom J
 
W

Willy Denoyette [MVP]

User defined control codes must be =>128 and <= 255. The operating system
reserves numbers under 128.

Willy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top