/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public string[] MulGetHardwareInfo(HardwareEnum hardType, string propKey,string checkKey) { List<string> strs = new List<string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value.ToString().Contains(checkKey)) { strs.Add(hardInfo.Properties["PNPDeviceID"].Value.ToString()); } } searcher.Dispose(); } return strs.ToArray(); } catch { return null; } finally { strs = null; } }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static dev_detail[] MulGetHardwareInfo(HardwareEnum hardType) { List <dev_detail> dev_list = new List <dev_detail>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { ManagementObjectCollection hardInfos = searcher.Get(); foreach (ManagementBaseObject hardInfo in hardInfos) { if (hardInfo.Properties["Name"].Value.ToString().Contains("COM")) { dev_detail dev = new dev_detail(); dev.dev_name = GetSerialPortName(hardInfo.Properties["Name"].Value.ToString()); dev.dev_discript = hardInfo.Properties["Name"].Value.ToString(); dev_list.Add(dev); } } searcher.Dispose(); } return(dev_list.ToArray()); } catch { return(null); } finally { dev_list = null; } }
/// <summary> /// WMI方式读取硬件信息 /// </summary> /// <param name="hardType">硬件类型</param> /// <param name="propKey">读取的硬件属性</param> /// <returns></returns> public static List <string> MulGetHardwareInfo(HardwareEnum hardType, string propKey) { List <string> strs = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { object val = hardInfo.Properties[propKey].Value; if (val == null) { continue; } string name = val.ToString(); if (name.Contains("COM")) { strs.Add(name); } } searcher.Dispose(); } return(strs); } catch { return(null); } finally { strs = null; } }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static string[] MulGetHardwareInfo(HardwareEnum hardType, string propKey) { List<string> strs = new List<string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { //if (hardInfo.Properties[propKey].Value.ToString().Contains("COM")) //{ strs.Add(hardInfo.Properties[propKey].Value.ToString()); //} } searcher.Dispose(); } return strs.ToArray(); } catch { return null; } finally { strs = null; } }
/// <summary> /// 遍历查找硬件 /// </summary> /// <param name="hardType">硬件名称</param> /// <param name="propKey">Key</param> /// <returns></returns> private static string[] GetHardwareInfo(HardwareEnum hardType, string propKey) { List <string> strs = new List <string>(); try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM " + hardType); //var hardInfos = searcher.Get(); foreach (ManagementObject hardInfo in searcher.Get()) { if (hardInfo.Properties[propKey].Value != null) { string str = hardInfo.Properties[propKey].Value.ToString(); strs.Add(str); } } return(strs.ToArray()); } catch { //MessageBox.Show(ex.Message); return(null); } finally { } }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType">硬件类型</param> /// <param name="propKey">筛选范围,默认为属性名</param> /// <param name="propValue">筛选条件,默认为COM</param> /// <returns></returns> public static string[] GetHardWare(HardwareEnum hardType, string propKey = "Name", string propValue = "COM") { var strs = new List <string>(); try { using (var searcher = new ManagementObjectSearcher("select * from " + hardType)) { foreach (var hardInfo in searcher.Get()) { if (hardInfo.Properties[propKey].Value != null) { if (hardInfo.Properties[propKey].Value.ToString().Contains(propValue)) { strs.Add(hardInfo.Properties[propKey].Value.ToString()); } } } } return(strs.ToArray()); } catch { return(null); } }
private static string[] GetHarewareInfo(HardwareEnum hardType, string propKey) { List <string> strs = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value != null) { String str = hardInfo.Properties[propKey].Value.ToString(); strs.Add(str); } } } return(strs.ToArray()); } catch { return(null); } finally { strs = null; } }//end of func GetHarewareInfo().
/// <summary> /// Get the system devices information with windows api. /// </summary> /// <param name="hardType">Device type.</param> /// <param name="propKey">the property of the device.</param> /// <returns></returns> private static string[] GetHarewareInfo(HardwareEnum hardType, string propKey) { List <string> strs = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value != null && hardInfo.Properties[propKey].Value.ToString().Contains("COM")) { strs.Add(hardInfo.Properties[propKey].Value.ToString()); } } searcher.Dispose(); } return(strs.ToArray()); } catch (Exception e) { ConsolePage.UnityIns.AddMessage(AConsoleMessage.MessageKindEnum.Error, e.Message); return(null); } finally { strs = null; } }
/// <summary> /// 取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static string MulGetHardwareInfo(HardwareEnum hardType, string propKey, string s) { if (s == "") { return(""); } else { string strs = ""; string a = ""; ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType); var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value != null) { a = hardInfo.Properties[propKey].Value.ToString(); if (s != null && a.Contains(s)) { strs = strs + a + "\n"; } } } return(strs); } }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static string[] MulGetHardwareInfo(HardwareEnum hardType, string propKey) { List <string> strs = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value != null) { strs.Add(hardInfo.Properties[propKey].Value.ToString()); } } searcher.Dispose(); } return(strs.ToArray()); } catch { return(null); } finally { strs = null; } }
/// <summary> /// 取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static string GetHardwareInfo(HardwareEnum hardType, string propKey) { ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType); var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey] != null) { return(hardInfo.Properties[propKey].Value.ToString()); } } return(""); }
public static string MulGetHardwareInfo(HardwareEnum hardType, string propKey, string propKey2) { string strs = ""; ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType); var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey] != null) { strs = strs + hardInfo.Properties[propKey].Value.ToString() + "******" + hardInfo.Properties[propKey2].Value.ToString() + "******"; } } return(strs); }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public List <string> MulGetHardwareInfo(HardwareEnum hardType, string propKey) { List <string> strsList = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value == null) { continue; } string strs; string name = hardInfo.Properties[propKey].Value.ToString(); string deviceid = (string)hardInfo.GetPropertyValue("DeviceID"); string pnpdDeviceid = (string)hardInfo.GetPropertyValue("PNPDeviceID"); string description = (string)hardInfo.GetPropertyValue("Description"); //if(deviceid==@"FTDIBUS\VID_0403+PID_6001+A50285BIA\0000") //查找特定id的设备 if (name.ToUpper().Contains("(COM")) { strs = name.ToString(); strsList.Add(strs); } } searcher.Dispose(); } return(strsList); } catch { return(null); } finally { strsList = null; } }
/// <summary> /// /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static string[] MulGetHardwareInfo(HardwareEnum hardType, string propKey) { List <string> Comstrs = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { ManagementObjectCollection hardInfos = searcher.Get(); foreach (ManagementBaseObject hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value == null) { continue; } if (hardInfo.Properties[propKey].Value.ToString().Contains("(COM")) { string com = hardInfo.Properties["Name"].Value.ToString(); string[] strcom = com.Split(new char[2] { '(', ')' }); //Comstrs.Add(strcom[1] + ":" + strcom[0]); int startIndex = com.IndexOf("COM"); string comName = com.Substring(startIndex, com.Length - startIndex - 1); Comstrs.Add(comName + ":" + com.Replace("(" + comName + ")", "")); //Comstrs.Add(hardInfo.Properties[propKey].Value.ToString()); } } searcher.Dispose(); } return(Comstrs.ToArray()); } catch { return(null); } finally { Comstrs = null; } }
public ManagementBaseObject[] GetManagementBaseObjects(HardwareEnum hardType) { List <ManagementBaseObject> strs = new List <ManagementBaseObject>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (ManagementBaseObject hardInfo in hardInfos) { strs.Add(hardInfo); } searcher.Dispose(); } return(strs.ToArray()); } catch { return(null); } }
/// <summary> /// 获取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static string[] GetHardwareInfo(HardwareEnum hardType, string propKey) { List <string> strs = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { try { if (!hardInfo.Properties[propKey].IsLocal) { continue; } if (hardInfo.Properties[propKey].Value.ToString().Contains("COM")) { strs.Add(hardInfo.Properties[propKey].Value.ToString()); } } catch { //忽略错误 continue; } } searcher.Dispose(); } return(strs.ToArray()); } catch { return(new string[0]); } finally { strs = null; } }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static List <ComList> MulGetHardwareInfo(HardwareEnum hardType, string propKey) { List <ComList> strs = new List <ComList>(); //string temp,va,vb; try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value != null) { if (hardInfo.Properties[propKey].Value.ToString().Contains("COM")) { ComList comList = new ComList(); string temp = hardInfo.Properties[propKey].Value.ToString(); string va = temp.Substring(temp.IndexOf("(") + 1, temp.IndexOf(")") - (temp.IndexOf("(") + 1)); string vb = temp.Substring(0, temp.IndexOf("(")); comList.ComNum = va; comList.Description = va + ":" + vb; strs.Add(comList); } } } searcher.Dispose(); } return(strs); } catch { return(null); } finally { strs = null; } }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <param name="filter"></param> /// <returns></returns> public static string[] MulGetHardwareInfo(HardwareEnum hardType, string propKey, string filter = "COM") { List <string> strs = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value != null) { if (hardInfo.Properties[propKey].Value.ToString().Contains(filter)) { strs.Add(hardInfo.Properties[propKey].Value.ToString()); //foreach (var item in hardInfo.Properties) //{ // System.Diagnostics.Debug.WriteLine(item.Name + ":" + item.Value); //} //System.Console.WriteLine(); } } } searcher.Dispose(); } return(strs.ToArray()); } catch { return(null); } finally { strs = null; } }
/// <summary> /// WMI取硬件信息 /// </summary> /// <param name="hardType"></param> /// <param name="propKey"></param> /// <returns></returns> public static List <string> MulGetHardwareInfo(HardwareEnum hardType, string propKey) { List <string> strs = new List <string>(); try { //using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) //using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\cimv2", "SELECT * FROM Win32_SerialPort")) ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity"); foreach (ManagementObject obj in searcher.Get()) { if (null != obj.Properties[propKey]) { if (null != obj.Properties[propKey].Value) { if (obj.Properties["Name"].Value.ToString().Contains("COM")) { strs.Add(obj.Properties[propKey].Value.ToString()); } else if (obj.Properties["Caption"].Value.ToString().Contains("COM")) { strs.Add(obj.Properties["Caption"].Value.ToString()); } } } } searcher.Dispose(); return(strs); } catch { return(null); } finally { strs = null; } }
private static string[] GetHarewareInfo(HardwareEnum hardType, string propKey) { List<string> strs = new List<string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType)) { var hardInfos = searcher.Get(); foreach (var hardInfo in hardInfos) { if (hardInfo.Properties[propKey].Value != null) { String str = hardInfo.Properties[propKey].Value.ToString(); strs.Add(str); } } } return strs.ToArray(); } catch { return null; } finally { strs = null; } }