![](/img/trans.png)
[英]How to start or stop IIS and also a Windows Service in remote machine using C#
[英]How do I start/stop/restart a windows service on a remote machine using .net
目前我正在開發啟動/停止/重啟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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.