如何以编程方式停止/启动远程盒子上的 Windows 服务? [英] How can I programmatically stop/start a windows service on a remote box?

查看:28
本文介绍了如何以编程方式停止/启动远程盒子上的 Windows 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个控制台或 Click Once WinForms 应用程序,它将以编程方式停止和/或启动远程框上的 Windows 服务.

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.

两个盒子都运行 .NET 3.5 - 有哪些 .NET API 可以实现这一点?

Both boxes are running .NET 3.5 - what .NET API's are available to accomplish this?

推荐答案

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

这篇关于如何以编程方式停止/启动远程盒子上的 Windows 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆