I want to write a console or Click Once WinForms app that will programmatically stop and/or start a windows service on a remote box.
Both boxes are running .NET 3.5 - what .NET API's are available to accomplish this?
While still in the command prompt type: SC \COMPUTERNAME stop SERVICENAME and press enter. This will tell the remote service to stop, it will not auto refresh when it stops so you have to manually check, you can do this by typing: SC \COMPUTERNAME query SERVICENAME. Main Areas of Contribution: General Networking |
Method 1: Using Command SC It's a built-in command line since Windows XP. It interacts with local and remote services quite easily like this: SC \computername STOP servicename. SC \computername START servicename.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With