public static LogicaldiskCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, System.String[] selectedProperties) { if ((mgmtScope == null)) { if ((statMgmtScope == null)) { mgmtScope = new System.Management.ManagementScope(); mgmtScope.Path.NamespacePath = "root\\cimv2"; } else { mgmtScope = statMgmtScope; } } System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new System.Management.SelectQuery("Win32_Logicaldisk", condition, selectedProperties)); System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); enumOptions.EnsureLocatable = true; ObjectSearcher.Options = enumOptions; return new LogicaldiskCollection(ObjectSearcher.Get()); }
/// <summary> /// HACK: Microsoft CDC driver (usbser.sys) does not register properly as a serial port /// It needs serenum.sys upper port filter which causes problems of its own... /// /// </summary> /// <param name="ports"></param> private static void PatchInZModemSerials(List <SerialPortInfo> ports) { /* SiLabs licensed USB to serial driver PID/VID */ const string SILABS_VID_PID = @"USB\VID_10C4&PID_81E8"; /* Zephyr VID (not specific on PID) */ const string ZEPHYR_VID = @"USB\VID_22F3"; string pnpDevId; int startIndex; int length; System.Management.ManagementScope scope; System.Management.ObjectQuery query; System.Management.ManagementObjectSearcher searcher; System.Management.ManagementObjectCollection returnCollection; System.Management.EnumerationOptions opt = new System.Management.EnumerationOptions(); try { /* get the data NOW, don't put off the query until it is required (30sec timeout) */ opt.ReturnImmediately = false; opt.Timeout = new TimeSpan(0, 0, 30); /* define scope, in this case, this machine */ scope = new System.Management.ManagementScope(@"root\CIMV2"); /* set the query, get all information on the serial ports on the system */ query = new System.Management.ObjectQuery("SELECT * from Win32_SerialPort"); /* stick two together into a search */ searcher = new System.Management.ManagementObjectSearcher(scope, query, opt); /* Run the query */ returnCollection = searcher.Get(); foreach (var oReturn in returnCollection) { pnpDevId = oReturn["PNPDeviceID"] as string; pnpDevId = pnpDevId.ToUpper(); // Vista / Win7 seem to use upper case PID/VID/GUID /* Checks to see if the candidate mySerialPort is a zephyr Serial Port */ if ((pnpDevId.LastIndexOf(SILABS_VID_PID) > -1) || (pnpDevId.LastIndexOf(ZEPHYR_VID) > -1)) { /* Extract the serial number from the PnP mySerialPort ID */ startIndex = pnpDevId.LastIndexOf(@"\") + 1; length = pnpDevId.LastIndexOf(@"_") - startIndex; if (length < 0) { length = pnpDevId.Length - startIndex; } /* If port not already known, add to list */ string serial = pnpDevId.Substring(startIndex, length); string portName = oReturn["DeviceID"] as string; string caption = oReturn["Caption"] as string; var search = ports.FirstOrDefault(item => item.Name == portName); if (search == null) { System.Diagnostics.Debug.WriteLine("Found: " + oReturn["DeviceID"] + " " + oReturn["Caption"]); SerialPortInfo spi = new SerialPortInfo(); spi.SerialName = serial; spi.Name = portName; spi.FriendlyName = caption; spi.Description = caption; spi.Manufacturer = "Zephyr"; spi.Driver = "usbser.sys"; ports.Add(spi); } } } } catch { } }
public static LogicaldiskCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { if ((mgmtScope == null)) { if ((statMgmtScope == null)) { mgmtScope = new System.Management.ManagementScope(); mgmtScope.Path.NamespacePath = "root\\cimv2"; } else { mgmtScope = statMgmtScope; } } System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); pathObj.ClassName = "Win32_Logicaldisk"; pathObj.NamespacePath = "root\\cimv2"; System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); if ((enumOptions == null)) { enumOptions = new System.Management.EnumerationOptions(); enumOptions.EnsureLocatable = true; } return new LogicaldiskCollection(clsObject.GetInstances(enumOptions)); }