private void Initialize(ISWbemObject wbemObj) { try { ISWbemObjectPath path = (ISWbemObjectPath)wbemObj.Path_; //get the property ISWbemPropertySet props = (ISWbemPropertySet)wbemObj.Properties_; prop = props.Item(propName, 0); if (path.IsClass) { genus = 1; classProp = prop; } else //instance { genus = 2; classProp = ((ISWbemPropertySet)wmiClassObj.Properties_).Item(propName, 0); } mgmtProp = mgmtObj.Properties[propName]; mgmtClassProp = mgmtClassObj.Properties[propName]; } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); } }
/// <summary> /// Given an instance of an association object and a path to one of its /// endpoints (the "source"), this method returns the role of the other endpoint /// (the "target") in this association. /// </summary> /// <param name="assocInstance"> </param> /// <param name="sourcePath"> </param> static public String GetAssocTargetRole(ISWbemObject assocInstance, ISWbemObjectPath sourcePath) { try { IEnumerator enumAssocProps = ((IEnumerable)(assocInstance.Properties_)).GetEnumerator(); while (enumAssocProps.MoveNext()) { ISWbemProperty curProp = (ISWbemProperty)enumAssocProps.Current; if (curProp.CIMType != WbemCimtypeEnum.wbemCimtypeReference) { continue; } else { //confirm that this is not the source if ((String.Compare(curProp.get_Value().ToString(), sourcePath.Path, true)) != 0) { return(curProp.Name); } } } return(String.Empty); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(String.Empty); } }
// // CONSTRUCTORS // // <doc> // <desc> // Main constructor. // </desc> // </doc> public WMIInstanceNode(ISWbemObject instObj, ISWbemObject classObj) { 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 } wmiObj = instObj; wmiClassObj = classObj; ISWbemObjectPath wbemPath = wmiObj.Path_; path = wbemPath.Path; serverName = wbemPath.Server; nsName = wbemPath.Namespace; className = wbemPath.Class; IsNewInstance = (path == string.Empty); } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); throw (exc); } }
/// <summary> /// Given an instance of an association object and a path to one of its /// endpoints (the "source"), this method returns "path" to the other endpoint /// (the "target"). /// </summary> /// <param name="assocInstance"> </param> /// <param name="sourcePath"> </param> static public String GetAssocTargetClass(ISWbemObject assocInstance, ISWbemObjectPath sourcePath) { try { IEnumerator enumAssocProps = ((IEnumerable)(assocInstance.Properties_)).GetEnumerator(); while (enumAssocProps.MoveNext()) { ISWbemProperty curProp = (ISWbemProperty)enumAssocProps.Current; if (curProp.CIMType != WbemCimtypeEnum.wbemCimtypeReference) { continue; } else { //get CIMTYPE property qualifier value String refValue = curProp.Qualifiers_.Item("CIMTYPE", 0).get_Value().ToString(); //get rid of "ref:" prefix: refValue = refValue.Substring(4); //confirm that this is not the source if ((String.Compare(refValue, sourcePath.Class, true) != 0) && (String.Compare(refValue, sourcePath.Path, true) != 0)) { //if this is a path, leave only the class name, //which is the part after the last backslash char[] separ = new char[] { '\\' }; string[] pathParts = refValue.Split(separ); refValue = pathParts[pathParts.Length - 1]; return(refValue); } } } return(String.Empty); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(String.Empty); } }
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); } }
/// <summary> /// note that Properties_ on ISWbemObject doesn't return system properties, /// so need to reconstruct them: __SERVER, __PATH, __GENUS are available through /// SWbemObjectPath; __DYNASTY, __DERIVATION can be accessed through SWbemObjct.Derivation_ /// </summary> private void Initialize() { try { ISWbemObjectPath path = (ISWbemObjectPath)wmiObj.Path_; if (path.IsClass) { GENUS = 1; } else //instance { GENUS = 2; } SystemPropertyDictionary.Add("__GENUS", GENUS); CLASS = path.Class; SystemPropertyDictionary.Add("__CLASS", CLASS); NAMESPACE = path.Namespace; SystemPropertyDictionary.Add("__NAMESPACE", NAMESPACE); PATH = path.Path; SystemPropertyDictionary.Add("__PATH", PATH); RELPATH = path.RelPath; SystemPropertyDictionary.Add("__RELPATH", RELPATH); SERVER = path.Server; SystemPropertyDictionary.Add("__SERVER", SERVER); //get PROPERTY_COUNT ISWbemPropertySet props = (ISWbemPropertySet)wmiObj.Properties_; IEnumerator eProps = ((IEnumerable)props).GetEnumerator(); while (eProps.MoveNext()) { PROPERTY_COUNT++; } SystemPropertyDictionary.Add("__PROPERTY_COUNT", PROPERTY_COUNT); //get inheritance-related properties Object[] oaDerivation = (Object[])wmiObj.Derivation_; if (oaDerivation.Length == 0) { DYNASTY = CLASS; } else { SUPERCLASS = oaDerivation[0].ToString(); DYNASTY = oaDerivation[oaDerivation.Length - 1].ToString(); } SystemPropertyDictionary.Add("__SUPERCLASS", SUPERCLASS); SystemPropertyDictionary.Add("__DYNASTY", DYNASTY); DERIVATION = new string[oaDerivation.Length]; Array.Copy(oaDerivation, DERIVATION, oaDerivation.Length); SystemPropertyDictionary.Add("__DERIVATION", DERIVATION); IsNewInstance = ((GENUS == 2) && (PATH == string.Empty)); } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); } }