When using System.Management; I'm not able to use any of it's methods/objects except Instrumentation
When using System.Management; I'm not able to use any of it's methods/objects except Instrumentation.
If I try to use ManagementObjectSearcher I get an error.
Error 1 The type or namespace name 'ManagementObjectSearcher' could not be found (are you missing a using directive or an assembly reference?
I'm trying to get the following Code to compile so that I can tell if a laptop is docked or not.
using System;using System.Management;using System.Windows.Forms;namespace WMISample{ public class MyWMIQuery { public static void Main() { try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_SystemEnclosure"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_SystemEnclosure instance"); Console.WriteLine("-----------------------------------"); if(queryObj["ChassisTypes"] == null) Console.WriteLine("ChassisTypes: {0}", queryObj["ChassisTypes"]); else { UInt16[] arrChassisTypes = (UInt16[])(queryObj["ChassisTypes"]); foreach (UInt16 arrValue in arrChassisTypes) { Console.WriteLine("ChassisTypes: {0}", arrValue); } } } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } }}