文章标题

来源:互联网 发布:基恩士视觉软件 编辑:程序博客网 时间:2024/05/16 18:31

WMI必须引用System.Management命名空间

WMI的两种查询方式

WQL方式

ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_OperatingSystem");foreach (ManagementObject mo in mos.Get()){ txtProductID.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() =>    {        ProductID.Text = (string)mo["SerialNumber"];    }));}

数据对象方式

ManagementClass cimobject2 = new ManagementClass("Win32_ComputerSystem");ManagementObjectCollection moc2 = cimobject2.GetInstances();foreach (ManagementObject mo1 in moc2){    txtSystemType.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() =>    {        SystemType.Text = mo1.Properties["SystemType"].Value.ToString();    }));}

两种方式大同小异

查看不同的对象所包含的内容,使用 运行→wbemtest,通过WQL语句进行查询。

0 0
原创粉丝点击