using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
using SystemManagement;
namespace Ex_
{
public partial class Form : Form
{
public Form()
{
InitializeComponent();
}
private void button_Click(object sender EventArgs e)
{
//指定生成 WMI 连接所需的所有设置
ConnectionOptions op = new ConnectionOptions();
opUsername = administrator;
//远程计算机用户名称
opPassword = ;
//远程计算机用户密码
//设置操作管理范围
ManagementScope scope = new ManagementScope(\\\\ + + \\root\\cimv op);
scopeConnect();
//将此 ManagementScope 连接到实际的 WMI 范围
ObjectQuery oq = new ObjectQuery(SELECT * FROM Win_OperatingSystem);
ManagementObjectSearcher query = new ManagementObjectSearcher(scope oq);
//得到WMI控制
ManagementObjectCollection queryCollection = queryGet();
foreach (ManagementObject obj in queryCollection)
{
objInvokeMethod(ShutDown null); //执行关闭远程计算机reboot为重新启动
}
}
}
}