How can I programmatically stop/start a windows service on a remote box?

You can also do this from a command console using the sc command:

 sc <server> start [service name]
 sc <server> stop [service name]

Use

sc <server> query | find "SERVICE_NAME"

to get a list of service names.

The option <server> has the form \\ServerName

Example

sc \\MyServer stop schedule will stop the Scheduler service.


in C#:

var sc = new System.ServiceProcess.ServiceController("MyService", "MyRemoteMachine");
sc.Start();
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running);
sc.Stop();
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped);