void QueryNamespaces() { FormSplash.ShowForm("Searching for WMI Namespaces... Please, wait"); RecurseNamespaces("root", treeNS.Nodes.Add("root", "root", 1, 2).Nodes); treeNS.Nodes[0].Expand(); xDoc = new XDocument(new XElement("root")); AddXNodeRecursive(xDoc.Root, treeNS.Nodes[0]); SaveNamespacesTree(); FormSplash.CloseForm(); }
void RecurseNamespaces(string path, TreeNodeCollection nodes) { try { ManagementClass mc = new ManagementClass( new ManagementScope(path), new ManagementPath("__namespace"), null); foreach (ManagementObject mo in mc.GetInstances()) { string name = path + "\\" + mo["Name"].ToString(); nsCount++; string s = mo["Name"].ToString(); FormSplash.AddItem(name); RecurseNamespaces(name, nodes.Add(s, s, 1, 2).Nodes); } } catch (ManagementException e) { SetError(e.Message, path); } }
void GetClasses(string ns) { FormSplash.ShowForm("Searching for WMI Classes... Please, wait"); try { ManagementObjectSearcher searcher = new ManagementObjectSearcher( new ManagementScope(ns), new SelectQuery("meta_class"), null); foreach (ManagementClass c in searcher.Get()) { string name = c["__CLASS"].ToString(); nClasses++; AddClass(name, c); FormSplash.AddItem(name); } } catch (Exception e) { SetError(e.Message, ns); } FormSplash.CloseForm(); }
void SetError(string msg, string path) { FormSplash.AddMsg(msg + ": " + path); DeleteNode(path); }