心静自然凉~

一杯清茶、二盏淡酒、邀三五知己,诉七八句心语,道九分珍重,怀十分真诚,或伤感、或快乐,无现实之隔阂 、无世俗之势利,如此人生,不亦乐乎!

导航

如何利用WMI远程重启远程计算机

Posted on 2007-02-10 00:57  Leo.Zhu  阅读(1170)  评论(0编辑  收藏  举报

using System;
using System.Management;
namespace WMI3
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)"); Console.WriteLine("mailto:Written%2002/01/02%20By%20John%20O'Donnell%20-%20csharpconsulting@hotmail.com");
Console.WriteLine("========================================
=================================");
//连接远程计算机
ConnectionOptions co = new ConnectionOptions(); co.Username = "john" co.Password = "john" System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\192.168.1.2\\root\\cimv2", co);
//查询远程计算机
System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");

ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms,oq); ManagementObjectCollection queryCollection1 = query1.Get(); foreach( ManagementObject mo in queryCollection1 ) { string[] ss={""}; mo.InvokeMethod("Reboot",ss); Console.WriteLine(mo.ToString()); } } } }