/// <summary> /// Find Device by options /// </summary> /// <param name="_type">dev_type.Description/HardwareID/PNPDeviceID/PNPClass</param> /// <param name="_class">Default is Win32_PnPEntity</param> /// <param name="_input">Target device</param> /// <returns>get or not</returns> public static bool FindDev(dev_type _type, string _class, string _input) { ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM " + _class);//Win32_PnPEntity if (searcher.Get() != null) { foreach (ManagementObject device in searcher.Get()) { bool blGetThisOne = false; switch (_type) { case dev_type.Description: { if (device["Description"] != null && device["Description"].ToString().ToLower().Contains(_input.ToLower())) { blGetThisOne = true; } break; } case dev_type.HardwareID: { if (device["HardwareID"] != null && device["HardwareID"].ToString().ToLower().Contains(_input.ToLower())) { blGetThisOne = true; } break; } case dev_type.PNPClass: { if (device["PNPClass"] != null && device["PNPClass"].ToString().ToLower().Contains(_input.ToLower())) { blGetThisOne = true; } break; } case dev_type.PNPDeviceID: { if (device["PNPDeviceID"] != null && device["PNPDeviceID"].ToString().ToLower().Contains(_input.ToLower())) { blGetThisOne = true; } break; } default: { break; } } if (blGetThisOne) { objects_internal.Add(device); } } } if (objects_internal.Count == 0) { return(false); } return(true); }
/// <summary> /// Find Device by options /// </summary> /// <param name="_type">dev_type.Description/HardwareID/PNPDeviceID/PNPClass</param> /// <param name="_input">Target device</param> /// <returns>true/false</returns> public static bool FindDev(dev_type _type, string _input) { bool blRet = FindDev(_type, @"Win32_PnPEntity", _input); return(blRet); }