码迷,mamicode.com
首页 > Windows程序 > 详细

c#访问远程计算机的Windows Service状态

时间:2015-05-21 17:03:37      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

 1 static void Main(string[] args)
 2 {
 3     ConnectionOptions op = new ConnectionOptions();
// 登陆远程计算机的远程,
4 op.Username = "Domain\\Domainuser"; 5 op.Password = "password"; 6 // 该处不能使用ip必须是"计算机名称.域名\root\cimv2" 7 ManagementScope scope = new ManagementScope(@"\\Servername.Domain\root\cimv2", op); 8 scope.Connect(); 9 ManagementPath path = new ManagementPath("Win32_Service"); 10 using(ManagementClass services = new ManagementClass(scope, path, null)) 11 { 12 foreach (ManagementObject service in services.GetInstances()) 13 { 14 Console.WriteLine("{0}:{1}",service.GetPropertyValue("Name").ToString(),service.GetPropertyValue("State").ToString()); 15 } 16 } 17 18 Console.ReadKey(); 19 }

 

运行结果,果然不负众望。

参考:

1,)http://www.codeproject.com/Articles/36268/Monitor-and-Manage-Services-on-Remote-Machines

2,)http://www.codeitive.com/0HJgVkjVeq/check-status-of-services-that-run-in-a-remote-computer-using-c.html

c#访问远程计算机的Windows Service状态

标签:

原文地址:http://www.cnblogs.com/yy3b2007com/p/4520023.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!