Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 300
Guy Avatar asked Jan 21 '09 22:01

Guy


People also ask

How do I stop a Windows service remotely?

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 |

How do I start and stop Windows services on a remote computer?

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.


1 Answers

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); 
like image 80
galets Avatar answered Sep 19 '22 16:09

galets