How do I start/stop/restart a windows service on a remote machine using .net
Currently I am developing desktop application that start/stop/restart windows services.
public 开发者_Go百科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.
You will need to instantiate the ServiceController with the overloaded constructor that accepts a machine name, like this:
ServiceController service = new ServiceController(serviceName, machineName);
精彩评论