using System.Management; ManagementBaseObject mbo = new ManagementBaseObject(); mbo["PropertyName"] = "PropertyValue"; // Accessing the value of a property string propertyValue = mbo["PropertyName"].ToString();
using System.Management; ManagementBaseObject mbo = new ManagementBaseObject("Win32_Process"); mbo["CommandLine"] = "notepad.exe"; ManagementObjectCollection mocProcess = new ManagementObjectSearcher(mbo).Get(); foreach (ManagementObject mo in mocProcess) { Console.WriteLine(mo["ProcessId"]); }This example demonstrates how to use the ManagementBaseObject class to execute a WMI query by specifying a WMI class name and filtering criteria. The example searches for all instances of the Win32_Process class where the CommandLine property is set to "notepad.exe", and then writes the value of the ProcessId property to the console. The System.Management.ManagementBaseObject class is included in the System.Management.dll library, which is part of the .NET Framework.