111,094
社区成员




private void button1_Click(object sender, EventArgs e)
{
ConnectionOptions options = new ConnectionOptions
{
Username = this.textBox1.Text,
Password = this.textBox2.Text
};
ManagementScope scope = new ManagementScope(@"\\" + this.textBox3.Text + @"\root\cimv2", options);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectCollection objects = new ManagementObjectSearcher(scope, query).Get();
foreach (ManagementObject obj2 in objects)
{
if (this.radioButton1.Checked)
{
obj2.InvokeMethod("reboot", null);//重启
}
else
{
obj2.InvokeMethod("ShutDown", null);//关机
}
}
}