public static ISWbemObject GetClassObject(String server, String ns, String className) { if (ns == string.Empty || className == string.Empty) { throw new ArgumentException(); } try { ISWbemLocator wbemLocator = WmiHelper.wbemLocator; //(ISWbemLocator)(new SWbemLocator()); ISWbemServices wbemServices = wbemLocator.ConnectServer(server, ns, "", //user: blank defaults to current logged-on user "", //password: blank defaults to current logged-on user "", //locale: blank for current locale "", //authority: NTLM or Kerberos. Blank lets DCOM negotiate. 0, //flags: reserved null); //context info: not needed here ISWbemObject classObj = wbemServices.Get(className, (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers, null); return(classObj); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(null); } }
// // CONSTRUCTORS // // <doc> // <desc> // Main constructor. // Parameters: // string server (in, machine name) // string pathIn (in, WMI path without the server name , e.g. "root\default:MyClass") // </desc> // </doc> public WMIClassNode(string pathIn) { try { path = pathIn; //parse the path to get server, namespace and class name Int32 separ = path.IndexOf("\\", 2); if (separ == -1) { //invalid path throw (new Exception("Invalid argument")); } serverName = path.Substring(2, separ - 2); pathNoServer = path.Substring(separ + 1, path.Length - separ - 1); //split pathNoServer into namespace and classname parts (':' is the separator) Int32 colon = pathNoServer.IndexOf(':', 0); if (colon == -1) { //invalid path throw (new Exception("Invalid argument")); } nsName = pathNoServer.Substring(0, colon); className = pathNoServer.Substring(colon + 1, pathNoServer.Length - colon - 1); //Get and cache wmiObj ISWbemLocator wbemLocator = (ISWbemLocator)(new SWbemLocator()); wbemServices = wbemLocator.ConnectServer(serverName, nsName, "", //user: blank defaults to current logged-on user "", //password: blank defaults to current logged-on user "", //locale: blank for current locale "", //authority: NTLM or Kerberos. Blank lets DCOM negotiate. 0, //flags: reserved null); //context info: not needed here if (wbemServices == null) { throw new Exception("Could not connect to WMI"); } wmiObj = wbemServices.Get(className, 0, //(int)WbemFlagEnum.wbemFlagUseAmendedQualifiers, null); if (wmiObj == null) { throw new Exception("Could not get WMI object" + path); } } catch (Exception exc) { MessageBox.Show("Exception: " + exc.Message + "\n\rTrace: " + exc.StackTrace); throw (exc); } }
/// <summary> /// The object retrieves its serialization info. /// </summary> public WMIAssocGroupNode(SerializationInfo info, StreamingContext context) { try { try { rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res", // Name of the resource. ".", // Use current directory. null); } catch (Exception) { //do nothing, will use static RM } //De-serialize string data mambers String associationPath = info.GetString("associationPath"); String targetClass = info.GetString("targetClass"); String targetRole = info.GetString("targetRole"); //De-serialize strings necessary to restore the source object String sourcePath = info.GetString("sourcePath"); String sourceNS = info.GetString("sourceNS"); String sourceServer = info.GetString("sourceServer"); //Restore SWbemObject for "source" ISWbemLocator wbemLocator = WmiHelper.WbemLocator; //(ISWbemLocator)(new SWbemLocator()); ISWbemServices wbemServices = wbemLocator.ConnectServer(sourceServer, sourceNS, "", //user: blank defaults to current logged-on user "", //password: blank defaults to current logged-on user "", //locale: blank for current locale "", //authority: NTLM or Kerberos. Blank lets DCOM negotiate. 0, //flags: reserved null); //context info: not needed here ISWbemObject sourceInst = wbemServices.Get(sourcePath, (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers, null); theComp = new AssocGroupComponent(sourceInst, associationPath, targetClass, targetRole); } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); throw (exc); } }
/// <summary> /// The object retrieves its serialization info. /// </summary> public ExtrinsicEventQueryNode(SerializationInfo info, StreamingContext context) { try { try { rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res", // Name of the resource. ".", // Use current directory. null); } catch (Exception) { //do nothing, will use static RM } serverName = info.GetString("Server"); nsName = info.GetString("NS"); query = info.GetString("Query"); state = SubscriptionState.Stopped; rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res", // Name of the resource. ".", // Use current directory. null); //Get and cache wbemServices ISWbemLocator wbemLocator = WmiHelper.WbemLocator; //(ISWbemLocator)(new SWbemLocator()); wbemServices = wbemLocator.ConnectServer(serverName, nsName, "", //user: blank defaults to current logged-on user "", //password: blank defaults to current logged-on user "", //locale: blank for current locale "", //authority: NTLM or Kerberos. Blank lets DCOM negotiate. 0, //flags: reserved null); //context info: not needed here if (wbemServices == null) { throw new Exception(WMISys.GetString("WMISE_WMIConnectFailed")); } browseObject = new ExtrinsicEventQueryComponent(serverName, nsName, query, this); } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); throw (exc); } }
public static ISWbemObject GetClassObject(ISWbemObject objIn) { if (objIn == null) { throw new ArgumentException(); } try { ISWbemObjectPath path = objIn.Path_; if (path.IsClass) { return(objIn); } ISWbemLocator wbemLocator = WmiHelper.wbemLocator; //(ISWbemLocator)(new SWbemLocator()); ISWbemServices wbemServices = wbemLocator.ConnectServer(path.Server, path.Namespace, "", //user: blank defaults to current logged-on user "", //password: blank defaults to current logged-on user "", //locale: blank for current locale "", //authority: NTLM or Kerberos. Blank lets DCOM negotiate. 0, //flags: reserved null); //context info: not needed here ISWbemObject classObj = wbemServices.Get(path.Class, (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers, null); return(classObj); } catch (Exception e) { //MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(null); } }
// private NewChildNode newChildNode = null; // // CONSTRUCTORS // // <doc> // <desc> // Main constructor. // Parameters: // string server (in, machine name) // string pathIn (in, WMI path without the server name , e.g. "root\default:MyClass") // </desc> // </doc> public WMIClassNode(string pathIn) { try { try { rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res", // Name of the resource. ".", // Use current directory. null); } catch (Exception) { //do nothing, will use static RM } path = pathIn; //parse the path to get server, namespace and class name Int32 separ = path.IndexOf("\\", 2); if (separ == -1) { //invalid path throw (new ArgumentException(WMISys.GetString("WMISE_InvalidPath", pathIn), "pathIn")); } serverName = path.Substring(2, separ - 2); pathNoServer = path.Substring(separ + 1, path.Length - separ - 1); //split pathNoServer into namespace and classname parts (':' is the separator) Int32 colon = pathNoServer.IndexOf(':', 0); if (colon == -1) { //invalid path throw (new ArgumentException(WMISys.GetString("WMISE_InvalidPath, pathIn"), "pathIn")); } nsName = pathNoServer.Substring(0, colon); className = pathNoServer.Substring(colon + 1, pathNoServer.Length - colon - 1); //Get and cache wmiObj ISWbemLocator wbemLocator = WmiHelper.WbemLocator; //(ISWbemLocator)(new SWbemLocator()); wbemServices = wbemLocator.ConnectServer(serverName, nsName, "", //user: blank defaults to current logged-on user "", //password: blank defaults to current logged-on user "", //locale: blank for current locale "", //authority: NTLM or Kerberos. Blank lets DCOM negotiate. 0, //flags: reserved null); //context info: not needed here wmiObj = wbemServices.Get(className, (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers, null); } catch (Exception exc) { //MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); throw (exc); } }
public SelectWMIClassTreeDialog(String server, ClassFilters filters, StringTable selClasses /*TODO: credentials */ ) { try { try { rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res", // Name of the resource. ".", // Use current directory. null); } catch (Exception) { //do nothing, will use static RM } currentFilters = filters; machineName = server; selectedClasses = selClasses; this.Text = WMISys.GetString("WMISE_ClassSelectorLbl"); this.AcceptButton = okBtn; this.AutoScaleBaseSize = (Size) new Point(5, 13); this.BorderStyle = FormBorderStyle.FixedSingle; this.CancelButton = cancelBtn; int dlgWidth = 527; int dlgHeight = 480; this.ClientSize = (Size) new Point(dlgWidth, dlgHeight); //this.add_KeyUp(new KeyEventHandler(this.OnKeyUp)); this.ShowInTaskbar = false; labelSearch.Location = new Point(16, 16); labelSearch.Size = (Size) new Point(200, 13); labelSearch.TabStop = false; labelSearch.Text = WMISys.GetString("WMISE_ClassSelectorLblSearch"); editSearch.Location = new Point(16, 33); editSearch.Size = (Size) new Point(200, 20); editSearch.TabStop = true; editSearch.TextChanged += new EventHandler(this.SearchPattern_changed); editSearch.AcceptsReturn = true; //??? editSearch.TabIndex = 0; btnGo.Location = new Point(226, 33); btnGo.TabStop = true; btnGo.Text = WMISys.GetString("WMISE_ClassSelectorBtnSearch"); btnGo.Click += new EventHandler(this.Search_click); classList.Location = new Point(16, 63); classList.Size = (Size) new Point(200, 270); classList.ShowPlusMinus = true; classList.ShowLines = true; classList.BeforeExpand += (new TreeViewCancelEventHandler(this.BeforeNodeExpand)); classList.DoubleClick += (new EventHandler(this.Add_click)); classList.BeforeCollapse += (new TreeViewCancelEventHandler(this.BeforeNodeCollapse)); classList.AfterSelect += (new TreeViewEventHandler(this.AfterNodeSelect)); classList.KeyUp += (new KeyEventHandler(this.OnTreeKeyUp)); classList.HideSelection = false; classList.FullRowSelect = true; //Image symbols = Image.FromFile("symbols.bmp"); //imgList.Images.AddStrip(symbols); imgList.TransparentColor = defaultBackColor; //didn't help!!!!!!! if (rm != null) { imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.closed_fol.bmp"), defaultBackColor); imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.open_fol.bmp"), defaultBackColor); imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.class.bmp"), defaultBackColor); imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.classassoc.bmp"), defaultBackColor); imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.abstr1.bmp"), defaultBackColor); imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.abstr2.bmp"), defaultBackColor); imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.abstr_assoc1.bmp"), defaultBackColor); //SCHEMA_ASSOC_ABSTRACT1 imgList.Images.Add((Image)rm.GetObject("Microsoft.VSDesigner.WMI.abstr_assoc2.bmp"), defaultBackColor); //SCHEMA_ASSOC_ABSTRACT2 } else { imgList.Images.Add((Image) new Bitmap(GetType(), "closed_fol.bmp"), defaultBackColor); imgList.Images.Add((Image) new Bitmap(GetType(), "open_fol.bmp"), defaultBackColor); imgList.Images.Add((Image) new Bitmap(GetType(), "class.bmp"), defaultBackColor); imgList.Images.Add((Image) new Bitmap(GetType(), "classassoc.bmp"), defaultBackColor); imgList.Images.Add((Image) new Bitmap(GetType(), "abstr1.bmp"), defaultBackColor); imgList.Images.Add((Image) new Bitmap(GetType(), "abstr2.bmp"), defaultBackColor); imgList.Images.Add((Image) new Bitmap(GetType(), "abstr_assoc1.bmp"), defaultBackColor); //SCHEMA_ASSOC_ABSTRACT1 imgList.Images.Add((Image) new Bitmap(GetType(), "abstr_assoc2.bmp"), defaultBackColor); //SCHEMA_ASSOC_ABSTRACT2 } //classList.ImageList = imgList; /* * TODO: * ADD * MORE IMAGES * TO THE STRIP AND USE THE STRIP * closed & open folder, assoc folders, obj groups etc.? */ /* * * TODO: USE TRANSPARENT COLOR * RIGHT NOW, BITMAPS HAVE WHITE INSTEAD OF TRANSPARENT */ btnAdd.Location = new Point(226, 150); btnAdd.TabStop = true; btnAdd.Text = WMISys.GetString("WMISE_ClassSelectorBtnAdd"); btnAdd.Click += new EventHandler(this.Add_click); btnAdd.Enabled = false; btnRemove.Location = new Point(226, 200); btnRemove.TabStop = true; btnRemove.Text = WMISys.GetString("WMISE_ClassSelectorBtnRemove"); btnRemove.Click += new EventHandler(this.Remove_click); btnRemove.Enabled = false; labelSelected.Location = new Point(311, 43); labelSelected.Size = (Size) new Point(200, 20); labelSelected.TabStop = false; labelSelected.Text = WMISys.GetString("WMISE_ClassSelectorSelClassesLbl"); selectedClassList.Location = new Point(311, 63); selectedClassList.Size = (Size) new Point(200, 270); selectedClassList.SelectionMode = SelectionMode.MultiExtended; selectedClassList.Sorted = true; //initialize selected class list String[] arSel = selectedClasses.ToArray(); for (int i = 0; i < arSel.Length; i++) { selectedClassList.Items.Add(arSel[i]); } selectedClassList.Click += new EventHandler(this.AfterClassSelect); selectedClassList.KeyUp += new KeyEventHandler(this.OnClassListKeyUp); selectedClassList.DoubleClick += (new EventHandler(this.Remove_click)); /* * chkShowData.Checked = ((currentFilters & SchemaFilters.NoData) == 0); * chkShowData.Location = new Point(500, 370); * chkShowData.Text = "Data"; * chkShowData.Click += new EventHandler(this.Filter_click); * chkShowData.Visible = false; * * chkShowSystem.Checked = ((currentFilters & SchemaFilters.NoSystem) == 0); * chkShowSystem.Location = new Point(550, 370); * chkShowSystem.Text = "System"; * chkShowSystem.Click += new EventHandler(this.Filter_click); * chkShowSystem.Visible = false; * * chkShowEvent.Checked = ((currentFilters & SchemaFilters.NoEvent) == 0); * chkShowEvent.Location = new Point(500, 400); * chkShowEvent.Text = "Event"; * chkShowEvent.Click += new EventHandler(this.Filter_click); * chkShowEvent.Visible = false; * * chkShowAbstract.Checked = ((currentFilters & SchemaFilters.NoAbstract) == 0); * chkShowAbstract.Location = new Point( 550, 400); * chkShowAbstract.Text = "Abstract"; * chkShowAbstract.Click += new EventHandler(this.Filter_click); * chkShowAbstract.Visible = false; */ descr.Text = ""; descr.Location = new Point(16, 342); descr.Size = (Size) new Point(500, 75); descr.Multiline = true; descr.ReadOnly = true; descr.ScrollBars = ScrollBars.Vertical; okBtn.Text = WMISys.GetString("WMISE_OK"); okBtn.TabIndex = 1; okBtn.Location = new Point(350, 427); okBtn.DialogResult = DialogResult.OK; okBtn.Click += new EventHandler(this.OK_click); cancelBtn.Text = WMISys.GetString("WMISE_Cancel"); cancelBtn.TabIndex = 2; cancelBtn.Location = new Point(436, 427); cancelBtn.DialogResult = DialogResult.Cancel; this.Controls.All = new Control[] { cancelBtn, okBtn, classList, selectedClassList, //chkShowAbstract, //chkShowSystem, //chkShowEvent, //chkShowData, labelSearch, labelSelected, editSearch, btnGo, btnAdd, btnRemove, descr }; wbemLocator = WmiHelper.WbemLocator; //(ISWbemLocator)(new SWbemLocator()); EnumNamespaces("root", 0); } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); } }