如何从一台服务器找出另一台服务器上运行的Windows服务状态?

时间:2013-04-09 07:59:54

标签: c# vb.net

通常,当需要知道现有服务器中的服务状态之一意味着通过粘贴下面的代码从服务控制器中找到结果很容易:

ServiceController sc = new ServiceController("servicename");

if  ((sc.Status.Equals(ServiceControllerStatus.Stopped)) ||
 (sc.Status.Equals(ServiceControllerStatus.StopPending)))
{
  // Start the service if the current status is stopped.
  sc.Start();
} 

在这里,我想知道另一台机器的服务状态,我怎样才能找到结果,任何人都能指导我这个场景。

1 个答案:

答案 0 :(得分:-1)

ServiceController的另一个构造函数将机器名称作为第二个参数。 http://msdn.microsoft.com/en-us/library/ssbk2tf3.aspx

你试过吗?