private bool ShowClasses(TreeNode curNode) { //show hourglass Cursor curSave = classList.Cursor; classList.Cursor = Cursors.WaitCursor; try { //check that this is a namespace: if (curNode.Parent != null) { return(false); } curNode.Nodes.Clear(); ISWbemServices services = (ISWbemServices)wbemLocator.ConnectServer(machineName, curNode.Text, "", "", "", "", 0, null); ISWbemObjectSet objSet = services.SubclassesOf("", 0, null); IEnumerator eClasses = ((IEnumerable)objSet).GetEnumerator(); SortedList classNameList = new SortedList(100); while (eClasses.MoveNext()) { ISWbemObject obj = (ISWbemObject)eClasses.Current; string childName = FilterPass(obj); if (childName != string.Empty) { classNameList.Add(childName, childName); } } for (int i = 0; i < classNameList.Count; i++) { TreeNode child = new TreeNode(classNameList.GetByIndex(i).ToString()); curNode.Nodes.Add(child); } classList.Cursor = curSave; return(true); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); classList.Cursor = curSave; return(false); } }
private bool EnumNamespaces(String parent, int num) //recursively adds namespaces to the drop-down box { try { try { wbemServices = wbemLocator.ConnectServer(machineName, parent, "", "", "", "", 0, null); } catch (Exception e) { //could not connect to the namespace //The most common cause is "Access denied" if (parent.ToLower() == "root") { //could not connect to Root, put error description text in the treeview TreeNode errNode = new TreeNode(e.Message); classList.Nodes.Add(num, errNode); } return(false); } //show the node TreeNode dummy = new TreeNode(""); TreeNode[] children = new TreeNode[] { dummy }; TreeNode nsNode = new TreeNode(parent, //(int)schema_icons.SCHEMA_NS_CLOSED, //(int)schema_icons.SCHEMA_NS_CLOSED, children); nsNode.Collapse(); classList.Nodes.Add(num, nsNode); ISWbemObjectSet objSet = wbemServices.InstancesOf("__NAMESPACE", 0, null); IEnumerator eInstances = ((IEnumerable)objSet).GetEnumerator(); while (eInstances.MoveNext()) { num++; ISWbemObject obj = (ISWbemObject)eInstances.Current; ISWbemPropertySet props = (ISWbemPropertySet)obj.Properties_; string NameOut = ""; string curName = props.Item("Name", 0).get_Value().ToString(); //skip localized namespace //NOTE: this assumes that localized namespaces are always leaf if (curName.ToUpper().IndexOf("MS_", 0) == 0) { continue; } //skip root\security namespace (we don't want to expose it) if (curName.ToUpper() == "SECURITY" && parent.ToUpper() == "ROOT") { continue; } //skip root\directory\ldap namespace (BUGBUG: change this in Beta2 when we can do asynchronous class enumerations) if (curName.ToUpper() == "LDAP" && parent.ToUpper() == "ROOT\\DIRECTORY") { continue; } if (parent != "") { NameOut = parent + "\\" + curName; } else { NameOut = curName; } EnumNamespaces(NameOut, num); } return(true); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(false); } }