Reputation: 1069
Currently I am developing desktop application that start/stop/restart windows services.
public static void StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
// ...
}
}
Now I want code to perform same action on remote system(other system on the same network).
Thanks.
Upvotes: 4
Views: 11414
Reputation: 14387
You will need to instantiate the ServiceController with the overloaded constructor that accepts a machine name, like this:
ServiceController service = new ServiceController(serviceName, machineName);
Upvotes: 6