コード例 #1
0
        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));
            }
        }
コード例 #2
0
        /// <summary>
        ///     Retrieves the default property.
        /// </summary>
        /// <returns>
        ///     the default property, or null if there are no
        ///     properties
        /// </returns>
        PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
        {
            //returns first property
            ISWbemPropertySet props  = (ISWbemPropertySet)wmiObj.Properties_;
            IEnumerator       eProps = ((IEnumerable)props).GetEnumerator();

            eProps.MoveNext();

            if (eProps.Current == null)
            {
                return(null);
            }

            String defPropName = ((ISWbemProperty)eProps.Current).Name;

            return(new WMIPropertyDescriptor(mgmtObj,
                                             mgmtClassObj,
                                             wmiObj,
                                             wmiClassObj,
                                             defPropName,
                                             !IsNewInstance));
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        /// <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));
            }
        }
コード例 #5
0
        /// <summary>
        ///     Retrieves an array of properties that the given component instance
        ///     provides.  This may differ from the set of properties the class
        ///     provides.  If the component is sited, the site may add or remove
        ///     additional properties.
        /// </summary>
        /// <returns>
        ///     an array of properties this component surfaces.
        /// </returns>
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
        {
            //NOTE: this re-initializing of mgmtObj and mgmtClassObj is a workaround:
            //apparently, the cached pointers that were created on a different thread
            //don't work: Interop marshalling problems?

            mgmtObj = null;
            mgmtObj = new ManagementObject(wmiObj.Path_.Path);

            mgmtClassObj = null;
            mgmtClassObj = new ManagementObject(wmiClassObj.Path_.Path);

            ISWbemPropertySet props  = (ISWbemPropertySet)wmiObj.Properties_;
            IEnumerator       eProps = ((IEnumerable)props).GetEnumerator();

            PropertyDescriptor[] propDescrArray = new PropertyDescriptor[((ISWbemPropertySet)props).Count + NUM_OF_SYSTEM_PROPS];
            if (propDescrArray.Length != 0)
            {
                int counter = 0;
                while (eProps.MoveNext())
                {
                    ISWbemProperty curProp = (ISWbemProperty)eProps.Current;

                    if (GENUS == 2)
                    {
                        //get the property on the class object: to get to "Values" qualifier
                        curProp = wmiClassObj.Properties_.Item(curProp.Name, 0);
                    }

                    /*
                     * if (WmiHelper.IsValueMap(curProp))
                     * {
                     *      //MessageBox.Show("Value map property " + ((ISWbemProperty)eProps.Current).Name);
                     *      propDescrArray[counter++] = new WMIEnumPropertyDescriptor(mgmtObj,
                     *                                                                                                                      mgmtClassObj,
                     *                                                                                                                      wmiObj,
                     *                                                                                                                      wmiClassObj,
                     *                                                                                                                      curProp.Name,
                     *                                                                                                                      !IsNewInstance);
                     *
                     * }
                     * else
                     */
                    {
                        propDescrArray[counter++] = new WMIPropertyDescriptor(mgmtObj,
                                                                              mgmtClassObj,
                                                                              wmiObj,
                                                                              wmiClassObj,
                                                                              curProp.Name,
                                                                              !IsNewInstance);
                    }
                }

                //add system properties
                IDictionaryEnumerator enumSys = (IDictionaryEnumerator)((IEnumerable)SystemPropertyDictionary).GetEnumerator();

                while (enumSys.MoveNext())
                {
                    propDescrArray[counter++] = new WMISystemPropertyDescriptor(wmiObj,
                                                                                enumSys.Key.ToString(),
                                                                                enumSys.Value);
                }
            }

            return(new PropertyDescriptorCollection(propDescrArray));
        }
コード例 #6
0
        private void Initialize()
        {
            try
            {
                this.TableName = wmiObj.Path_.Class;

                propNameColumn = new DataColumn(WMISys.GetString("WMISE_PropTable_ColumnName"));

                propNameColumn.AllowNull = false;
                propNameColumn.Unique    = true;
                propNameColumn.DataType  = typeof(string);

                propTypeColumn           = new DataColumn(WMISys.GetString("WMISE_PropTable_ColumnType"));
                propTypeColumn.AllowNull = false;
                propTypeColumn.DataType  = typeof(string);

                propValueColumn = new DataColumn(WMISys.GetString("WMISE_PropTable_ColumnValue"));
                propValueColumn.DefaultValue = null;

                propDescrColumn              = new DataColumn(WMISys.GetString("WMISE_PropTable_ColumnDescription"));
                propDescrColumn.ReadOnly     = true;
                propDescrColumn.DefaultValue = string.Empty;
                propDescrColumn.DataType     = typeof(string);

                if (showOperators)
                {
                    operatorColumn = new DataColumn(WMISys.GetString("WMISE_PropTable_ColumnComparison"),
                                                    typeof(ComparisonOperators));
                }
                //operatorColumn.AllowNull = false;

                /*
                 * ValueEditor dropDownEditor = new ValueEditor();
                 * dropDownEditor.Style = ValueEditorStyles.DropdownArrow;
                 * operatorColumn.DataValueEditorType = dropDownEditor.GetType();
                 */


                if (showKeys)
                {
                    propIsKey              = new DataColumn(WMISys.GetString("WMISE_PropTable_ColumnIsKey"), typeof(Boolean));
                    propIsKey.AllowNull    = false;
                    propIsKey.DefaultValue = false;
                }

                if (showOrigin)
                {
                    propOrigin              = new DataColumn(WMISys.GetString("WMISE_PropTable_ColumnIsLocal"), typeof(Boolean));
                    propOrigin.AllowNull    = false;
                    propOrigin.DefaultValue = true;
                }

                //set read/write permissions on columns
                //Note that DefaultView takes care of the rest of the restrictions
                //(see below)
                if (gridMode == GridMode.EditMode)
                {
                    propNameColumn.ReadOnly  = true;
                    propTypeColumn.ReadOnly  = true;
                    propValueColumn.ReadOnly = false;

                    if (showOrigin)
                    {
                        propOrigin.ReadOnly = true;
                    }
                    if (showKeys)
                    {
                        propIsKey.ReadOnly = true;
                    }
                }

                if (gridMode == GridMode.DesignMode && showOrigin)
                {
                    propOrigin.ReadOnly = true;
                }

                Columns.Add(propNameColumn);
                Columns.Add(propTypeColumn);
                if (showOperators)
                {
                    //operatorColumn.DataValueEditorType = typeof(OperatroDataColumnEditor);
                    operatorColumn.ReadOnly = false;
                    Columns.Add(operatorColumn);
                }

                Columns.Add(propValueColumn);
                //Columns.Add(propDescrColumn);

                if (showOrigin)
                {
                    Columns.Add(propOrigin);
                }
                if (showKeys)
                {
                    Columns.Add(propIsKey);
                }


                ISWbemPropertySet props = wmiObj.Properties_;

                IEnumerator propEnum = ((IEnumerable)props).GetEnumerator();

                while (propEnum.MoveNext())
                {
                    ISWbemProperty prop = (ISWbemProperty)propEnum.Current;


                    if (propFilters == PropertyFilters.NoInherited &&
                        !prop.IsLocal)
                    {
                        continue;                               //skip this property
                    }

                    DataRow propRow = NewRow();

                    propRow[propNameColumn]  = prop.Name;
                    propRow[propTypeColumn]  = CIMTypeMapper.ToString(prop.CIMType);
                    propRow[propValueColumn] = prop.get_Value();
                    //propRow[propDescrColumn] = WmiHelper.GetPropertyDescription(prop, wmiObj);
                    if (showOperators)
                    {
                        propRow[operatorColumn] = "=";
                    }

                    //set property origin column

                    if (showOrigin)
                    {
                        if (prop.IsLocal)
                        {
                            propRow[propOrigin] = true;
                        }
                        else
                        {
                            propRow[propOrigin] = false;
                        }
                    }

                    if (showKeys)
                    {
                        propRow[propIsKey] = WmiHelper.IsKeyProperty(prop);
                    }


                    Rows.Add(propRow);
                }
                //TODO: add system properties here (if PropertyFilters.ShowAll)

                this.CaseSensitive = false;
                this.RowChanged   += new DataRowChangeEventHandler(this.RowChangedEventHandler);
                this.RowChanging  += new DataRowChangeEventHandler(this.RowChangingEventHandler);


                DataView view = this.DefaultView;
                switch (gridMode)
                {
                case (GridMode.ViewMode):
                {
                    view.AllowEdit   = false;                                   //wmi raid 2866?
                    view.AllowDelete = false;
                    view.AllowNew    = false;
                    break;
                }

                case (GridMode.EditMode):
                {
                    view.AllowEdit   = true;
                    view.AllowDelete = false;
                    view.AllowNew    = false;
                    break;
                }

                case (GridMode.DesignMode):
                {
                    view.AllowEdit   = true;
                    view.AllowDelete = true;
                    view.AllowNew    = true;
                    break;
                }
                }
            }

            catch (Exception exc)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace));
            }
        }