using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;//在资源管理器中添加引用System.Management
//VS2008,XP,控制台应用程序
namespace ConnectionPC
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("远程连接计算机");
//connect
ConnectionOptions conn = new ConnectionOptions();
Console.WriteLine("username:");
conn.Username = Console.ReadLine();
Console.WriteLine("password:");
conn.Password = Console.ReadLine();
ManagementScope maS = new ManagementScope("\\\\IP\\root\\cimv2", conn);
//use the connection to search
ObjectQuery objQ = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher maObjSea = new ManagementObjectSearcher(maS, objQ);
ManagementObjectCollection pCollection = maObjSea.Get();
//restart
foreach (ManagementObject mo in pCollection)
{
string[] ss = { "" };
mo.InvokeMethod("Reboot", ss);
Console.WriteLine(mo.ToString());
}
}
}
}