using System; using System.Collections.Generic; using System.Text; using System.Management; using System.Diagnostics; namespace Tango.SystemInfo { class WMIReader { public static IList GetPropertyValues(Connection WMIConnection, string SelectQuery, string className) { List hardwareList = new List(); ManagementScope connectionScope = WMIConnection.GetConnectionScope; List alProperties = new List(); SelectQuery msQuery = new SelectQuery(SelectQuery); ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(connectionScope, msQuery); try { foreach (ManagementObject item in searchProcedure.Get()) { SystemObject hardware = new SystemObject(); try { hardware.Name = item["Name"].ToString(); } catch { hardware.Name = item.ToString(); } hardwareList.Add(hardware); foreach (string property in XMLConfig.GetSettings(className)) { try { hardware.Properties.Add(new SystemObjectProperty() { Name = property, Value = item[property].ToString() }); } catch (SystemException) { //Debug.WriteLine($"System Exception on {className}, {property}"); } } } } catch (ManagementException e) { //Debug.WriteLine($"Management Exception on {className}"); } return hardwareList; } } }