using System;
using System.Management;

namespace WMI3
{
	class Class1
	{
		static void Main(string[] args)
		{
			Console.WriteLine("使用Windows Management Instrumentation (WMI)的实例");
					
			//连接到远程计算机
			ConnectionOptions co = new ConnectionOptions();
			co.Username = "administrator";
			co.Password = "sw78111";
			System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\162.105.106.96\\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());
			}
		}
	}
}
