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

后端 未结 9 1769
清歌不尽
清歌不尽 2020-11-27 05:17

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

9条回答
  •  盖世英雄少女心
    2020-11-27 05:46

    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);
    

提交回复
热议问题