private void WMIRecursiveSearch(string nameSpace, string computerName) { var wmiHelpers = new eWMI(); if (backgroundWorker.CancellationPending) { return; } try { var results = wmiHelpers.InvokeQuery(computerName, "Select Name from __Namespace", nameSpace); foreach (var result in results) { if (backgroundWorker.CancellationPending) { return; } string childNamespaceName = nameSpace + "\\" + result.GetPropertyValue("Name").ToString(); backgroundWorker.ReportProgress(1, childNamespaceName); WMIRecursiveSearch(childNamespaceName, computerName); } } catch { backgroundWorker.ReportProgress(1, nameSpace + "\\" + "Error getting child namespaces"); } }
private void backgroundWorkerBackgroundJob(object sender, DoWorkEventArgs e) { var wmiHelpers = new eWMI(); string computerName = ""; string nameSpace = ""; string wmiQuery = ""; string[] args; try { args = e.Argument as string[]; computerName = args[0]; nameSpace = args[1]; wmiQuery = args[2]; var results = wmiHelpers.InvokeQuery(computerName, wmiQuery, nameSpace); foreach (var result in results) { WMIInstance tempInstance = new WMIInstance(); foreach (var sysProperty in result.SystemProperties) { tempInstance.Properties.Add(new WMIInstanceProperty { PropertyName = sysProperty.Name, Type = sysProperty.Type.ToString(), Value = sysProperty.Value }); } foreach (var Property in result.Properties) { tempInstance.Properties.Add(new WMIInstanceProperty { PropertyName = Property.Name, Type = Property.Type.ToString(), Value = Property.Value }); } } } catch { throw; } }