+-

目前我正在开发启动/停止/重启 Windows服务的桌面应用程序.
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
{
// ...
}
}
现在我希望代码在远程系统(同一网络上的其他系统)上执行相同的操作.
谢谢.
最佳答案
您需要使用重载的接受机器名的构造函数来实例化ServiceController,如下所示:
ServiceController service = new ServiceController(serviceName, machineName);
点击查看更多相关文章
转载注明原文:c# – 如何使用.net在远程计算机上启动/停止/重新启动Windows服务 - 乐贴网