ManagementBaseObject.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Wmi / managed / System / Management / ManagementBaseObject.cs / 1305376 / ManagementBaseObject.cs

                            using System.Collections; 
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Runtime.Serialization; 
using System.Globalization;
using System.Security.Permissions; 
 
namespace System.Management
{ 
    /// 
    /// Describes the possible text formats that can be used with .
    /// 
    public enum TextFormat 
    {
        ///  
        /// Managed Object Format 
        /// 
        Mof = 0, 
        /// 
        /// XML DTD that corresponds to CIM DTD version 2.0
        /// 
        CimDtd20 = 1, 
        /// 
        /// XML WMI DTD that corresponds to CIM DTD version 2.0. 
        /// Using this value enables a few WMI-specific extensions, like embedded objects. 
        /// 
        WmiDtd20 = 2 
    };

    /// 
    ///    Describes the possible CIM types for properties, qualifiers, or method parameters. 
    /// 
    public enum CimType 
    { 
        /// 
        ///    Invalid Type 
        /// 
        None = 0,
        /// 
        ///    A signed 8-bit integer. 
        /// 
        SInt8 = 16, 
        ///  
        ///    An unsigned 8-bit integer.
        ///  
        UInt8 = 17,
        /// 
        ///    A signed 16-bit integer.
        ///  
        SInt16 = 2,
        ///  
        ///    An unsigned 16-bit integer. 
        /// 
        UInt16 = 18, 
        /// 
        ///    A signed 32-bit integer.
        /// 
        SInt32 = 3, 
        /// 
        ///    An unsigned 32-bit integer. 
        ///  
        UInt32 = 19,
        ///  
        ///    A signed 64-bit integer.
        /// 
        SInt64 = 20,
        ///  
        ///    An unsigned 64-bit integer.
        ///  
        UInt64 = 21, 
        /// 
        ///    A floating-point 32-bit number. 
        /// 
        Real32 = 4,
        /// 
        ///    A floating point 64-bit number. 
        /// 
        Real64 = 5, 
        ///  
        ///     A boolean.
        ///  
        Boolean = 11,
        /// 
        ///    A string.
        ///  
        String = 8,
        ///  
        ///     A date or time value, represented in a string in DMTF 
        ///       date/time format: yyyymmddHHMMSS.mmmmmmsUUU
        ///    where: 
        ///    yyyymmdd - is the date in year/month/day
        ///    HHMMSS - is the time in hours/minutes/seconds
        ///    mmmmmm - is the number of microseconds in 6 digits
        ///    sUUU - is a sign (+ or -) and a 3-digit UTC offset 
        /// 
        DateTime = 101, 
        ///  
        ///    A reference to another object. This is represented by a
        ///       string containing the path to the referenced object 
        /// 
        Reference = 102,
        /// 
        ///     A 16-bit character. 
        /// 
        Char16 = 103, 
        ///  
        ///    An embedded object.
        ///    Note that embedded objects differ from references in that the embedded object 
        ///       doesn't have a path and its lifetime is identical to the lifetime of the
        ///       containing object.
        /// 
        Object = 13, 
    };
 
    ///  
    /// Describes the object comparison modes that can be used with .
    ///    Note that these values may be combined. 
    /// 
    [Flags]
    public enum ComparisonSettings
    { 
        /// 
        ///    A mode that compares all elements of the compared objects. 
        ///  
        IncludeAll = 0,
        ///  
        ///    A mode that compares the objects, ignoring qualifiers.
        /// 
        IgnoreQualifiers = 0x1,
        ///  
        ///     A mode that ignores the source of the objects, namely the server
        ///       and the namespace they came from, in comparison to other objects. 
        ///  
        IgnoreObjectSource = 0x2,
        ///  
        ///     A mode that ignores the default values of properties.
        ///       This value is only meaningful when comparing classes.
        /// 
        IgnoreDefaultValues = 0x4, 
        /// 
        ///    A mode that assumes that the objects being compared are instances of 
        ///       the same class. Consequently, this value causes comparison 
        ///       of instance-related information only. Use this flag to optimize
        ///       performance. If the objects are not of the same class, the results are undefined. 
        /// 
        IgnoreClass = 0x8,
        /// 
        ///     A mode that compares string values in a case-insensitive 
        ///       manner. This applies to strings and to qualifier values. Property and qualifier
        ///       names are always compared in a case-insensitive manner whether this flag is 
        ///       specified or not. 
        /// 
        IgnoreCase = 0x10, 
        /// 
        ///    A mode that ignores qualifier flavors. This flag still takes
        ///       qualifier values into account, but ignores flavor distinctions such as
        ///       propagation rules and override restrictions. 
        /// 
        IgnoreFlavor = 0x20 
    }; 

 
    internal enum QualifierType
    {
        ObjectQualifier,
        PropertyQualifier, 
        MethodQualifier
    } 
 

    //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC// 
    /// 
    ///     Contains the basic elements of a management
    ///       object. It serves as a base class to more specific management object classes.
    ///  
    //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
    [Serializable] 
    [ToolboxItem(false)] 
    public class ManagementBaseObject : Component, ICloneable, ISerializable
    { 
        // This field holds onto a WbemContext for the lifetime of the appdomain.  This should
        // preven Fastprox.dll from unloading prematurely (WMI bugs # 2998 and # 4118 - URT bug # 90889)
        //
 
        private static WbemContext lockOnFastProx = System.Management.Instrumentation.WMICapabilities.IsWindowsXPOrHigher()?null:new WbemContext();
 
        // 
        // The wbemObject is changed from a field to a property. This is to avoid major code churn and simplify the solution to
        // the problem where the Initialize call actually binds to the object. This occured even in cases like Get() whereby we 
        // ended up getting the object twice. Any direct usage of this property will cause a call to Initialize ( true ) to be made
        // (if not already done) indicating that we wish to bind to the underlying WMI object.
        //
        // See changes to Initialize 
        //
        internal IWbemClassObjectFreeThreaded wbemObject 
        { 
            get
            { 
                if (_wbemObject == null)
                {
                    Initialize(true);
                } 
                return _wbemObject;
            } 
            set 
            {
                _wbemObject = value; 
            }
        }

        internal IWbemClassObjectFreeThreaded _wbemObject ; 

        private PropertyDataCollection properties; 
        private PropertyDataCollection systemProperties; 
        private QualifierDataCollection qualifiers;
 
        /// 
        /// Initializes a new instance of the  class that is serializable.
        /// 
        /// The  to populate with data. 
        /// The destination (see  ) for this serialization.
        protected ManagementBaseObject(SerializationInfo info, StreamingContext context) 
        { 
            _wbemObject = info.GetValue("wbemObject", typeof(IWbemClassObjectFreeThreaded)) as IWbemClassObjectFreeThreaded;
            if (null == _wbemObject) 
                throw new SerializationException();
            properties = null;
            systemProperties = null;
            qualifiers = null; 
        }
 
        public new void Dispose() 
        {
            if (_wbemObject != null) 
            {
                _wbemObject.Dispose();
                _wbemObject = null;
            } 
            base.Dispose();
            GC.SuppressFinalize(this); 
        } 

        ///  
        ///    Provides the internal WMI object represented by a ManagementObject.
        ///    See remarks with regard to usage.
        /// 
        /// The  that references the requested WMI object.  
        /// 
        /// An  representing the internal WMI object. 
        ///  
        /// 
        ///    This operator is used internally by instrumentation code. It is not intended 
        ///       for direct use by regular client or instrumented applications.
        /// 
        public static explicit operator IntPtr(ManagementBaseObject managementObject)
        { 
            if(null == managementObject)
                return IntPtr.Zero; 
            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            //
            //managementObject.Initialize ( ) ;
            return (IntPtr)managementObject.wbemObject;
        } 

 
        //FXCop requests explicit demand of the SerializationFormatter permission 
        [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter=true)]
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) 
        {
            //
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            //
            // Initialize (  ) ; 
            info.AddValue("wbemObject", wbemObject, typeof(IWbemClassObjectFreeThreaded)); 
            info.AssemblyName = typeof(ManagementBaseObject).Assembly.FullName;
            info.FullTypeName = typeof(ManagementBaseObject).ToString(); 
        }

        protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        { 
            ((ISerializable)this).GetObjectData ( info, context ) ;
        } 
 
        // Factory
        ///  
        /// Factory for various types of base object
        /// 
        ///  IWbemClassObject 
        ///  The scope 
        internal static ManagementBaseObject GetBaseObject(
            IWbemClassObjectFreeThreaded wbemObject, 
            ManagementScope scope) 
        {
            ManagementBaseObject newObject = null; 

            if (_IsClass(wbemObject))
                newObject = ManagementClass.GetManagementClass(wbemObject, scope);
            else 
                newObject = ManagementObject.GetManagementObject(wbemObject, scope);
 
            return newObject; 
        }
 
        //Constructor
        internal ManagementBaseObject(IWbemClassObjectFreeThreaded wbemObject)
        {
            this.wbemObject = wbemObject; 
            properties = null;
            systemProperties = null; 
            qualifiers = null; 
        }
 
        /// 
        ///    Returns a copy of the object.
        /// 
        ///  
        ///    The new cloned object.
        ///  
        public virtual Object Clone() 
        {
            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter.
            //
            // Initialize ( ) ; 
            IWbemClassObjectFreeThreaded theClone = null;
 
            int status = wbemObject.Clone_(out theClone); 

            if (status < 0) 
            {
                if ((status & 0xfffff000) == 0x80041000)
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                else 
                    Marshal.ThrowExceptionForHR(status);
            } 
 
            return new ManagementBaseObject(theClone);
        } 

        internal virtual void Initialize ( bool getObject ) {}

        // 
        //Properties
        // 
 
        /// 
        /// Gets or sets a collection of  objects describing the properties of the 
        ///    management object.
        /// 
        /// 
        /// A  that represents the 
        ///    properties of the management object.
        ///  
        ///  
        public virtual PropertyDataCollection Properties
        { 
            get
            {
                Initialize ( true ) ;
 
                if (properties == null)
                    properties = new PropertyDataCollection(this, false); 
 
                return properties;
            } 
        }

        /// 
        ///    Gets or sets the collection of WMI system properties of the management object (for example, the 
        ///       class name, server, and namespace). WMI system property names begin with
        ///       "__". 
        ///  
        /// 
        /// A  that represents the system properties of the management object. 
        /// 
        /// 
        public virtual PropertyDataCollection SystemProperties
        { 
            get
            { 
                Initialize ( false ) ; 

                if (systemProperties == null) 
                    systemProperties = new PropertyDataCollection(this, true);

                return systemProperties;
            } 
        }
 
        ///  
        /// Gets or sets the collection of  objects defined on the management object.
        ///    Each element in the collection holds information such as the qualifier name, 
        ///    value, and flavor.
        /// 
        /// 
        /// A  that represents the qualifiers 
        ///    defined on the management object.
        ///  
        ///  
        public virtual QualifierDataCollection Qualifiers
        { 
            get
            {
                Initialize ( true ) ;
 
                if (qualifiers == null)
                    qualifiers = new QualifierDataCollection(this); 
 
                return qualifiers;
            } 
        }

        /// 
        ///    Gets or sets the path to the management object's class. 
        /// 
        ///  
        /// A  that represents the path to the management object's class. 
        /// 
        ///  
        ///    For example, for the \\MyBox\root\cimv2:Win32_LogicalDisk=
        ///       'C:' object, the class path is \\MyBox\root\cimv2:Win32_LogicalDisk
        ///       .
        ///  
        public virtual ManagementPath ClassPath
        { 
            get 
            {
                Object serverName = null; 
                Object scopeName = null;
                Object className = null;
                int propertyType = 0;
                int propertyFlavor = 0; 
                int status = (int)ManagementStatus.NoError;
 
                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
                // its getter. 
                //
                // Initialize ( ) ;
                status = wbemObject.Get_("__SERVER", 0, ref serverName, ref propertyType, ref propertyFlavor);
 
                if (status == (int)ManagementStatus.NoError)
                { 
                    status = wbemObject.Get_("__NAMESPACE", 0, ref scopeName, ref propertyType, ref propertyFlavor); 

                    if (status == (int)ManagementStatus.NoError) 
                        status = wbemObject.Get_("__CLASS", 0, ref className, ref propertyType, ref propertyFlavor);
                }

                if (status < 0) 
                {
                    if ((status & 0xfffff000) == 0x80041000) 
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); 
                    else
                        Marshal.ThrowExceptionForHR(status); 
                }

                ManagementPath classPath = new ManagementPath();
 
                // initialize in case of throw
                classPath.Server = String.Empty; 
                classPath.NamespacePath = String.Empty; 
                classPath.ClassName = String.Empty;
 
                // Some of these may throw if they are NULL
                try
                {
                    classPath.Server = (string)(serverName is System.DBNull ? "" : serverName); 
                    classPath.NamespacePath = (string)(scopeName is System.DBNull ? "" : scopeName);
                    classPath.ClassName = (string)(className is System.DBNull ? "" : className); 
                } 
                catch
                { 
                }

                return classPath;
            } 
        }
 
 
        //
        //Methods 
        //

        //******************************************************
        //[] operator by property name 
        //*****************************************************
        ///  
        ///     Gets access to property values through [] notation. 
        /// 
        /// The name of the property of interest.  
        /// 
        ///    An  containing the
        ///    value of the requested property.
        ///  
        public Object this[string propertyName]
        { 
            get { return GetPropertyValue(propertyName); } 
            set
            { 
                Initialize ( true ) ;
                try
                {
                    SetPropertyValue (propertyName, value); 
                }
                catch (COMException e) 
                { 
                    ManagementException.ThrowWithExtendedInfo(e);
                } 
            }
        }

        //***************************************************** 
        //GetPropertyValue
        //***************************************************** 
        ///  
        ///    Gets an equivalent accessor to a property's value.
        ///  
        /// The name of the property of interest. 
        /// 
        ///    The value of the specified property.
        ///  
        public Object GetPropertyValue(string propertyName)
        { 
            if (null == propertyName) 
                throw new ArgumentNullException ("propertyName");
 
            // Check for system properties
            if (propertyName.StartsWith ("__", StringComparison.Ordinal))
                return SystemProperties[propertyName].Value;
            else 
                return Properties[propertyName].Value;
        } 
 
        //******************************************************
        //GetQualifierValue 
        //*****************************************************
        /// 
        ///    Gets the value of the specified qualifier.
        ///  
        /// The name of the qualifier of interest. 
        ///  
        ///    The value of the specified qualifier. 
        /// 
        public Object GetQualifierValue(string qualifierName) 
        {
            return Qualifiers [qualifierName].Value;
        }
 
        //******************************************************
        //SetQualifierValue 
        //****************************************************** 
        /// 
        ///    Sets the value of the named qualifier. 
        /// 
        /// The name of the qualifier to set. This parameter cannot be null.
        /// The value to set.
        public void SetQualifierValue(string qualifierName, object qualifierValue) 
        {
            Qualifiers [qualifierName].Value = qualifierValue; 
        } 

 
        //*****************************************************
        //GetPropertyQualifierValue
        //******************************************************
        ///  
        ///    Returns the value of the specified property qualifier.
        ///  
        /// The name of the property to which the qualifier belongs.  
        /// The name of the property qualifier of interest. 
        ///  
        ///    The value of the specified qualifier.
        /// 
        public Object GetPropertyQualifierValue(string propertyName, string qualifierName)
        { 
            return Properties[propertyName].Qualifiers[qualifierName].Value;
        } 
 
        //*****************************************************
        //SetPropertyQualifierValue 
        //*****************************************************
        /// 
        ///    Sets the value of the specified property qualifier.
        ///  
        /// The name of the property to which the qualifier belongs.
        /// The name of the property qualifier of interest. 
        /// The new value for the qualifier. 
        public void SetPropertyQualifierValue(string propertyName, string qualifierName,
            object qualifierValue) 
        {
            Properties[propertyName].Qualifiers[qualifierName].Value = qualifierValue;
        }
 
        //*****************************************************
        //GetText 
        //****************************************************** 
        /// 
        ///    Returns a textual representation of the object in the specified format. 
        /// 
        /// The requested textual format. 
        /// 
        ///    The textual representation of the 
        ///       object in the specified format.
        ///  
        // 
        public string GetText(TextFormat format)
        { 
            string objText = null;
            int status = (int)ManagementStatus.NoError;

            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            // 
            switch(format)
            { 
                case TextFormat.Mof :

                    status = wbemObject.GetObjectText_(0, out objText);
 
                    if (status < 0)
                    { 
                        if ((status & 0xfffff000) == 0x80041000) 
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                        else 
                            Marshal.ThrowExceptionForHR(status);
                    }

                    return objText; 

                case TextFormat.CimDtd20 : 
                case TextFormat.WmiDtd20 : 

                    //This may throw on non-XP platforms... - should we catch ? 
                    IWbemObjectTextSrc wbemTextSrc = (IWbemObjectTextSrc)new WbemObjectTextSrc();
                    IWbemContext ctx = (IWbemContext)new WbemContext();
                    object v = (bool)true;
                    ctx.SetValue_("IncludeQualifiers", 0, ref v); 
                    ctx.SetValue_("IncludeClassOrigin", 0, ref v);
 
                    if (wbemTextSrc != null) 
                    {
                        status = wbemTextSrc.GetText_(0, 
                            (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(wbemObject)),
                            (uint)format, //note: this assumes the format enum has the same values as the underlying WMI enum !!
                            ctx,
                            out objText); 
                        if (status < 0)
                        { 
                            if ((status & 0xfffff000) == 0x80041000) 
                                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                            else 
                                Marshal.ThrowExceptionForHR(status);
                        }
                    }
 
                    return objText;
 
                default : 

                    return null; 
            }
        }

        ///  
        ///    Compares two management objects.
        ///  
        /// An object to compare with this instance. 
        /// 
        ///  if 
        ///  is an instance of  and represents
        ///    the same object as this instance; otherwise, .
        /// 
        public override bool Equals(object obj) 
        {
            bool result = false; 
 
            try
            { 
                //
                // Removed Initialize call since CompareTo calls Initialize.
                // its getter.
                // 
                // Initialize ( ) ;
 
                if (obj is ManagementBaseObject) 
                {
                    result = CompareTo ((ManagementBaseObject)obj, ComparisonSettings.IncludeAll); 
                }
                else
                {
                    return false; 
                }
            } 
            catch (ManagementException exc) 
            {
                if (exc.ErrorCode == ManagementStatus.NotFound) 
                {
                    //we could wind up here if Initialize() throws (either here or inside CompareTo())
                    //Since we cannot throw from Equals() imprelemtation and it is invalid to assume
                    //that two objects are different because they fail to initialize (this assumption causes bug 100527) 
                    //so, we can just compare these invalid paths "by value"
 
                    if (this is ManagementObject && obj is ManagementObject) 
                    {
                        int compareRes = String.Compare(((ManagementObject)this).Path.Path, 
                            ((ManagementObject)obj).Path.Path,
                            StringComparison.OrdinalIgnoreCase);
                        return (compareRes == 0);
                    } 
                }
                return false; 
            } 
            catch
            { 
                return false;
            }
            return result;
        } 

        ///  
        ///     Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. 
        ///        The hash code for ManagementBaseObjects is based on the MOF for the WbemObject that this instance is based on.  Two different ManagementBaseObject instances pointing to the same WbemObject in WMI will have the same mof and thus the same hash code.  Changing a property value of an object will change the hash code. 
        ///  
        /// 
        ///     A hash code for the current object. 
        /// 
        public override int GetHashCode() 
        {
            //            return base.GetHashCode(); 
 
            //This implementation has to match the Equals() implementation. In Equals(), we use
            //the WMI CompareTo() which compares values of properties, qualifiers etc. 
            //Probably the closest we can get is to take the MOF representation of the object and get it's hash code.
            int localHash = 0;
            try
            { 
                // GetText may throw if it cannot get a string for the mof for various reasons
                // This should be a very rare event 
                localHash = this.GetText(TextFormat.Mof).GetHashCode(); 
            }
            catch (ManagementException) 
            {
                // use the hash code of an empty string on failure to get the mof
                localHash = string.Empty.GetHashCode();
            } 
            catch (System.Runtime.InteropServices.COMException)
            { 
                // use the hash code of an empty string on failure to get the mof 
                localHash = string.Empty.GetHashCode();
            } 
            return localHash;
        }

        //***************************************************** 
        //CompareTo
        //****************************************************** 
        ///  
        ///    Compares this object to another, based on specified options.
        ///  
        /// The object to which to compare this object. 
        /// Options on how to compare the objects. 
        /// 
        ///  if the objects compared are equal 
        ///    according to the given options; otherwise, 
        ///    . 
        ///  
        public bool CompareTo(ManagementBaseObject otherObject, ComparisonSettings settings)
        { 
            if (null == otherObject)
                throw new ArgumentNullException ("otherObject");

            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            // 
            // Initialize ( ) ;
            bool result = false; 

            if (null != wbemObject)
            {
                int status = (int) ManagementStatus.NoError; 

                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on 
                // its getter.
                // 
                //otherObject.Initialize ( false ) ;

                status = wbemObject.CompareTo_((int) settings, otherObject.wbemObject);
 
                if ((int)ManagementStatus.Different == status)
                    result = false; 
                else if ((int)ManagementStatus.NoError == status) 
                    result = true;
                else if ((status & 0xfffff000) == 0x80041000) 
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                else if (status < 0)
                    Marshal.ThrowExceptionForHR(status);
            } 

            return result; 
        } 

        internal string ClassName 
        {
            get
            {
                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
                // its getter. 
                // 
                // Initialize ( ) ;
                object val = null; 
                int dummy1 = 0, dummy2 = 0;
                int status = (int)ManagementStatus.NoError;

                status = wbemObject.Get_ ("__CLASS", 0, ref val, ref dummy1, ref dummy2); 

                if (status < 0) 
                { 
                    if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); 
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
 
                if (val is System.DBNull)
                    return String.Empty; 
                else 
                    return ((string) val);
            } 
        }

        private static bool _IsClass(IWbemClassObjectFreeThreaded wbemObject)
        { 
            object val = null;
            int dummy1 = 0, dummy2 = 0; 
 
            int status = wbemObject.Get_("__GENUS", 0, ref val, ref dummy1, ref dummy2);
 
            if (status < 0)
            {
                if ((status & 0xfffff000) == 0x80041000)
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); 
                else
                    Marshal.ThrowExceptionForHR(status); 
            } 

            return ((int)val == (int)tag_WBEM_GENUS_TYPE.WBEM_GENUS_CLASS); 
        }

        internal bool IsClass
        { 
            get
            { 
                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
                // its getter. 
                //
                // Initialize ( ) ;
                return _IsClass(wbemObject);
            } 
        }
 
        ///  
        ///    Sets the value of the named property.
        ///  
        /// The name of the property to be changed.
        /// The new value for this property.
        public void SetPropertyValue (
            string propertyName, 
            object propertyValue)
        { 
            if (null == propertyName) 
                throw new ArgumentNullException ("propertyName");
 
            // Check for system properties
            if (propertyName.StartsWith ("__", StringComparison.Ordinal))
                SystemProperties[propertyName].Value = propertyValue;
            else 
                Properties[propertyName].Value = propertyValue;
        } 
 
    }//ManagementBaseObject
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System.Collections; 
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Runtime.Serialization; 
using System.Globalization;
using System.Security.Permissions; 
 
namespace System.Management
{ 
    /// 
    /// Describes the possible text formats that can be used with .
    /// 
    public enum TextFormat 
    {
        ///  
        /// Managed Object Format 
        /// 
        Mof = 0, 
        /// 
        /// XML DTD that corresponds to CIM DTD version 2.0
        /// 
        CimDtd20 = 1, 
        /// 
        /// XML WMI DTD that corresponds to CIM DTD version 2.0. 
        /// Using this value enables a few WMI-specific extensions, like embedded objects. 
        /// 
        WmiDtd20 = 2 
    };

    /// 
    ///    Describes the possible CIM types for properties, qualifiers, or method parameters. 
    /// 
    public enum CimType 
    { 
        /// 
        ///    Invalid Type 
        /// 
        None = 0,
        /// 
        ///    A signed 8-bit integer. 
        /// 
        SInt8 = 16, 
        ///  
        ///    An unsigned 8-bit integer.
        ///  
        UInt8 = 17,
        /// 
        ///    A signed 16-bit integer.
        ///  
        SInt16 = 2,
        ///  
        ///    An unsigned 16-bit integer. 
        /// 
        UInt16 = 18, 
        /// 
        ///    A signed 32-bit integer.
        /// 
        SInt32 = 3, 
        /// 
        ///    An unsigned 32-bit integer. 
        ///  
        UInt32 = 19,
        ///  
        ///    A signed 64-bit integer.
        /// 
        SInt64 = 20,
        ///  
        ///    An unsigned 64-bit integer.
        ///  
        UInt64 = 21, 
        /// 
        ///    A floating-point 32-bit number. 
        /// 
        Real32 = 4,
        /// 
        ///    A floating point 64-bit number. 
        /// 
        Real64 = 5, 
        ///  
        ///     A boolean.
        ///  
        Boolean = 11,
        /// 
        ///    A string.
        ///  
        String = 8,
        ///  
        ///     A date or time value, represented in a string in DMTF 
        ///       date/time format: yyyymmddHHMMSS.mmmmmmsUUU
        ///    where: 
        ///    yyyymmdd - is the date in year/month/day
        ///    HHMMSS - is the time in hours/minutes/seconds
        ///    mmmmmm - is the number of microseconds in 6 digits
        ///    sUUU - is a sign (+ or -) and a 3-digit UTC offset 
        /// 
        DateTime = 101, 
        ///  
        ///    A reference to another object. This is represented by a
        ///       string containing the path to the referenced object 
        /// 
        Reference = 102,
        /// 
        ///     A 16-bit character. 
        /// 
        Char16 = 103, 
        ///  
        ///    An embedded object.
        ///    Note that embedded objects differ from references in that the embedded object 
        ///       doesn't have a path and its lifetime is identical to the lifetime of the
        ///       containing object.
        /// 
        Object = 13, 
    };
 
    ///  
    /// Describes the object comparison modes that can be used with .
    ///    Note that these values may be combined. 
    /// 
    [Flags]
    public enum ComparisonSettings
    { 
        /// 
        ///    A mode that compares all elements of the compared objects. 
        ///  
        IncludeAll = 0,
        ///  
        ///    A mode that compares the objects, ignoring qualifiers.
        /// 
        IgnoreQualifiers = 0x1,
        ///  
        ///     A mode that ignores the source of the objects, namely the server
        ///       and the namespace they came from, in comparison to other objects. 
        ///  
        IgnoreObjectSource = 0x2,
        ///  
        ///     A mode that ignores the default values of properties.
        ///       This value is only meaningful when comparing classes.
        /// 
        IgnoreDefaultValues = 0x4, 
        /// 
        ///    A mode that assumes that the objects being compared are instances of 
        ///       the same class. Consequently, this value causes comparison 
        ///       of instance-related information only. Use this flag to optimize
        ///       performance. If the objects are not of the same class, the results are undefined. 
        /// 
        IgnoreClass = 0x8,
        /// 
        ///     A mode that compares string values in a case-insensitive 
        ///       manner. This applies to strings and to qualifier values. Property and qualifier
        ///       names are always compared in a case-insensitive manner whether this flag is 
        ///       specified or not. 
        /// 
        IgnoreCase = 0x10, 
        /// 
        ///    A mode that ignores qualifier flavors. This flag still takes
        ///       qualifier values into account, but ignores flavor distinctions such as
        ///       propagation rules and override restrictions. 
        /// 
        IgnoreFlavor = 0x20 
    }; 

 
    internal enum QualifierType
    {
        ObjectQualifier,
        PropertyQualifier, 
        MethodQualifier
    } 
 

    //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC// 
    /// 
    ///     Contains the basic elements of a management
    ///       object. It serves as a base class to more specific management object classes.
    ///  
    //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC//
    [Serializable] 
    [ToolboxItem(false)] 
    public class ManagementBaseObject : Component, ICloneable, ISerializable
    { 
        // This field holds onto a WbemContext for the lifetime of the appdomain.  This should
        // preven Fastprox.dll from unloading prematurely (WMI bugs # 2998 and # 4118 - URT bug # 90889)
        //
 
        private static WbemContext lockOnFastProx = System.Management.Instrumentation.WMICapabilities.IsWindowsXPOrHigher()?null:new WbemContext();
 
        // 
        // The wbemObject is changed from a field to a property. This is to avoid major code churn and simplify the solution to
        // the problem where the Initialize call actually binds to the object. This occured even in cases like Get() whereby we 
        // ended up getting the object twice. Any direct usage of this property will cause a call to Initialize ( true ) to be made
        // (if not already done) indicating that we wish to bind to the underlying WMI object.
        //
        // See changes to Initialize 
        //
        internal IWbemClassObjectFreeThreaded wbemObject 
        { 
            get
            { 
                if (_wbemObject == null)
                {
                    Initialize(true);
                } 
                return _wbemObject;
            } 
            set 
            {
                _wbemObject = value; 
            }
        }

        internal IWbemClassObjectFreeThreaded _wbemObject ; 

        private PropertyDataCollection properties; 
        private PropertyDataCollection systemProperties; 
        private QualifierDataCollection qualifiers;
 
        /// 
        /// Initializes a new instance of the  class that is serializable.
        /// 
        /// The  to populate with data. 
        /// The destination (see  ) for this serialization.
        protected ManagementBaseObject(SerializationInfo info, StreamingContext context) 
        { 
            _wbemObject = info.GetValue("wbemObject", typeof(IWbemClassObjectFreeThreaded)) as IWbemClassObjectFreeThreaded;
            if (null == _wbemObject) 
                throw new SerializationException();
            properties = null;
            systemProperties = null;
            qualifiers = null; 
        }
 
        public new void Dispose() 
        {
            if (_wbemObject != null) 
            {
                _wbemObject.Dispose();
                _wbemObject = null;
            } 
            base.Dispose();
            GC.SuppressFinalize(this); 
        } 

        ///  
        ///    Provides the internal WMI object represented by a ManagementObject.
        ///    See remarks with regard to usage.
        /// 
        /// The  that references the requested WMI object.  
        /// 
        /// An  representing the internal WMI object. 
        ///  
        /// 
        ///    This operator is used internally by instrumentation code. It is not intended 
        ///       for direct use by regular client or instrumented applications.
        /// 
        public static explicit operator IntPtr(ManagementBaseObject managementObject)
        { 
            if(null == managementObject)
                return IntPtr.Zero; 
            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            //
            //managementObject.Initialize ( ) ;
            return (IntPtr)managementObject.wbemObject;
        } 

 
        //FXCop requests explicit demand of the SerializationFormatter permission 
        [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter=true)]
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) 
        {
            //
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            //
            // Initialize (  ) ; 
            info.AddValue("wbemObject", wbemObject, typeof(IWbemClassObjectFreeThreaded)); 
            info.AssemblyName = typeof(ManagementBaseObject).Assembly.FullName;
            info.FullTypeName = typeof(ManagementBaseObject).ToString(); 
        }

        protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        { 
            ((ISerializable)this).GetObjectData ( info, context ) ;
        } 
 
        // Factory
        ///  
        /// Factory for various types of base object
        /// 
        ///  IWbemClassObject 
        ///  The scope 
        internal static ManagementBaseObject GetBaseObject(
            IWbemClassObjectFreeThreaded wbemObject, 
            ManagementScope scope) 
        {
            ManagementBaseObject newObject = null; 

            if (_IsClass(wbemObject))
                newObject = ManagementClass.GetManagementClass(wbemObject, scope);
            else 
                newObject = ManagementObject.GetManagementObject(wbemObject, scope);
 
            return newObject; 
        }
 
        //Constructor
        internal ManagementBaseObject(IWbemClassObjectFreeThreaded wbemObject)
        {
            this.wbemObject = wbemObject; 
            properties = null;
            systemProperties = null; 
            qualifiers = null; 
        }
 
        /// 
        ///    Returns a copy of the object.
        /// 
        ///  
        ///    The new cloned object.
        ///  
        public virtual Object Clone() 
        {
            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter.
            //
            // Initialize ( ) ; 
            IWbemClassObjectFreeThreaded theClone = null;
 
            int status = wbemObject.Clone_(out theClone); 

            if (status < 0) 
            {
                if ((status & 0xfffff000) == 0x80041000)
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                else 
                    Marshal.ThrowExceptionForHR(status);
            } 
 
            return new ManagementBaseObject(theClone);
        } 

        internal virtual void Initialize ( bool getObject ) {}

        // 
        //Properties
        // 
 
        /// 
        /// Gets or sets a collection of  objects describing the properties of the 
        ///    management object.
        /// 
        /// 
        /// A  that represents the 
        ///    properties of the management object.
        ///  
        ///  
        public virtual PropertyDataCollection Properties
        { 
            get
            {
                Initialize ( true ) ;
 
                if (properties == null)
                    properties = new PropertyDataCollection(this, false); 
 
                return properties;
            } 
        }

        /// 
        ///    Gets or sets the collection of WMI system properties of the management object (for example, the 
        ///       class name, server, and namespace). WMI system property names begin with
        ///       "__". 
        ///  
        /// 
        /// A  that represents the system properties of the management object. 
        /// 
        /// 
        public virtual PropertyDataCollection SystemProperties
        { 
            get
            { 
                Initialize ( false ) ; 

                if (systemProperties == null) 
                    systemProperties = new PropertyDataCollection(this, true);

                return systemProperties;
            } 
        }
 
        ///  
        /// Gets or sets the collection of  objects defined on the management object.
        ///    Each element in the collection holds information such as the qualifier name, 
        ///    value, and flavor.
        /// 
        /// 
        /// A  that represents the qualifiers 
        ///    defined on the management object.
        ///  
        ///  
        public virtual QualifierDataCollection Qualifiers
        { 
            get
            {
                Initialize ( true ) ;
 
                if (qualifiers == null)
                    qualifiers = new QualifierDataCollection(this); 
 
                return qualifiers;
            } 
        }

        /// 
        ///    Gets or sets the path to the management object's class. 
        /// 
        ///  
        /// A  that represents the path to the management object's class. 
        /// 
        ///  
        ///    For example, for the \\MyBox\root\cimv2:Win32_LogicalDisk=
        ///       'C:' object, the class path is \\MyBox\root\cimv2:Win32_LogicalDisk
        ///       .
        ///  
        public virtual ManagementPath ClassPath
        { 
            get 
            {
                Object serverName = null; 
                Object scopeName = null;
                Object className = null;
                int propertyType = 0;
                int propertyFlavor = 0; 
                int status = (int)ManagementStatus.NoError;
 
                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
                // its getter. 
                //
                // Initialize ( ) ;
                status = wbemObject.Get_("__SERVER", 0, ref serverName, ref propertyType, ref propertyFlavor);
 
                if (status == (int)ManagementStatus.NoError)
                { 
                    status = wbemObject.Get_("__NAMESPACE", 0, ref scopeName, ref propertyType, ref propertyFlavor); 

                    if (status == (int)ManagementStatus.NoError) 
                        status = wbemObject.Get_("__CLASS", 0, ref className, ref propertyType, ref propertyFlavor);
                }

                if (status < 0) 
                {
                    if ((status & 0xfffff000) == 0x80041000) 
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); 
                    else
                        Marshal.ThrowExceptionForHR(status); 
                }

                ManagementPath classPath = new ManagementPath();
 
                // initialize in case of throw
                classPath.Server = String.Empty; 
                classPath.NamespacePath = String.Empty; 
                classPath.ClassName = String.Empty;
 
                // Some of these may throw if they are NULL
                try
                {
                    classPath.Server = (string)(serverName is System.DBNull ? "" : serverName); 
                    classPath.NamespacePath = (string)(scopeName is System.DBNull ? "" : scopeName);
                    classPath.ClassName = (string)(className is System.DBNull ? "" : className); 
                } 
                catch
                { 
                }

                return classPath;
            } 
        }
 
 
        //
        //Methods 
        //

        //******************************************************
        //[] operator by property name 
        //*****************************************************
        ///  
        ///     Gets access to property values through [] notation. 
        /// 
        /// The name of the property of interest.  
        /// 
        ///    An  containing the
        ///    value of the requested property.
        ///  
        public Object this[string propertyName]
        { 
            get { return GetPropertyValue(propertyName); } 
            set
            { 
                Initialize ( true ) ;
                try
                {
                    SetPropertyValue (propertyName, value); 
                }
                catch (COMException e) 
                { 
                    ManagementException.ThrowWithExtendedInfo(e);
                } 
            }
        }

        //***************************************************** 
        //GetPropertyValue
        //***************************************************** 
        ///  
        ///    Gets an equivalent accessor to a property's value.
        ///  
        /// The name of the property of interest. 
        /// 
        ///    The value of the specified property.
        ///  
        public Object GetPropertyValue(string propertyName)
        { 
            if (null == propertyName) 
                throw new ArgumentNullException ("propertyName");
 
            // Check for system properties
            if (propertyName.StartsWith ("__", StringComparison.Ordinal))
                return SystemProperties[propertyName].Value;
            else 
                return Properties[propertyName].Value;
        } 
 
        //******************************************************
        //GetQualifierValue 
        //*****************************************************
        /// 
        ///    Gets the value of the specified qualifier.
        ///  
        /// The name of the qualifier of interest. 
        ///  
        ///    The value of the specified qualifier. 
        /// 
        public Object GetQualifierValue(string qualifierName) 
        {
            return Qualifiers [qualifierName].Value;
        }
 
        //******************************************************
        //SetQualifierValue 
        //****************************************************** 
        /// 
        ///    Sets the value of the named qualifier. 
        /// 
        /// The name of the qualifier to set. This parameter cannot be null.
        /// The value to set.
        public void SetQualifierValue(string qualifierName, object qualifierValue) 
        {
            Qualifiers [qualifierName].Value = qualifierValue; 
        } 

 
        //*****************************************************
        //GetPropertyQualifierValue
        //******************************************************
        ///  
        ///    Returns the value of the specified property qualifier.
        ///  
        /// The name of the property to which the qualifier belongs.  
        /// The name of the property qualifier of interest. 
        ///  
        ///    The value of the specified qualifier.
        /// 
        public Object GetPropertyQualifierValue(string propertyName, string qualifierName)
        { 
            return Properties[propertyName].Qualifiers[qualifierName].Value;
        } 
 
        //*****************************************************
        //SetPropertyQualifierValue 
        //*****************************************************
        /// 
        ///    Sets the value of the specified property qualifier.
        ///  
        /// The name of the property to which the qualifier belongs.
        /// The name of the property qualifier of interest. 
        /// The new value for the qualifier. 
        public void SetPropertyQualifierValue(string propertyName, string qualifierName,
            object qualifierValue) 
        {
            Properties[propertyName].Qualifiers[qualifierName].Value = qualifierValue;
        }
 
        //*****************************************************
        //GetText 
        //****************************************************** 
        /// 
        ///    Returns a textual representation of the object in the specified format. 
        /// 
        /// The requested textual format. 
        /// 
        ///    The textual representation of the 
        ///       object in the specified format.
        ///  
        // 
        public string GetText(TextFormat format)
        { 
            string objText = null;
            int status = (int)ManagementStatus.NoError;

            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            // 
            switch(format)
            { 
                case TextFormat.Mof :

                    status = wbemObject.GetObjectText_(0, out objText);
 
                    if (status < 0)
                    { 
                        if ((status & 0xfffff000) == 0x80041000) 
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                        else 
                            Marshal.ThrowExceptionForHR(status);
                    }

                    return objText; 

                case TextFormat.CimDtd20 : 
                case TextFormat.WmiDtd20 : 

                    //This may throw on non-XP platforms... - should we catch ? 
                    IWbemObjectTextSrc wbemTextSrc = (IWbemObjectTextSrc)new WbemObjectTextSrc();
                    IWbemContext ctx = (IWbemContext)new WbemContext();
                    object v = (bool)true;
                    ctx.SetValue_("IncludeQualifiers", 0, ref v); 
                    ctx.SetValue_("IncludeClassOrigin", 0, ref v);
 
                    if (wbemTextSrc != null) 
                    {
                        status = wbemTextSrc.GetText_(0, 
                            (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(wbemObject)),
                            (uint)format, //note: this assumes the format enum has the same values as the underlying WMI enum !!
                            ctx,
                            out objText); 
                        if (status < 0)
                        { 
                            if ((status & 0xfffff000) == 0x80041000) 
                                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                            else 
                                Marshal.ThrowExceptionForHR(status);
                        }
                    }
 
                    return objText;
 
                default : 

                    return null; 
            }
        }

        ///  
        ///    Compares two management objects.
        ///  
        /// An object to compare with this instance. 
        /// 
        ///  if 
        ///  is an instance of  and represents
        ///    the same object as this instance; otherwise, .
        /// 
        public override bool Equals(object obj) 
        {
            bool result = false; 
 
            try
            { 
                //
                // Removed Initialize call since CompareTo calls Initialize.
                // its getter.
                // 
                // Initialize ( ) ;
 
                if (obj is ManagementBaseObject) 
                {
                    result = CompareTo ((ManagementBaseObject)obj, ComparisonSettings.IncludeAll); 
                }
                else
                {
                    return false; 
                }
            } 
            catch (ManagementException exc) 
            {
                if (exc.ErrorCode == ManagementStatus.NotFound) 
                {
                    //we could wind up here if Initialize() throws (either here or inside CompareTo())
                    //Since we cannot throw from Equals() imprelemtation and it is invalid to assume
                    //that two objects are different because they fail to initialize (this assumption causes bug 100527) 
                    //so, we can just compare these invalid paths "by value"
 
                    if (this is ManagementObject && obj is ManagementObject) 
                    {
                        int compareRes = String.Compare(((ManagementObject)this).Path.Path, 
                            ((ManagementObject)obj).Path.Path,
                            StringComparison.OrdinalIgnoreCase);
                        return (compareRes == 0);
                    } 
                }
                return false; 
            } 
            catch
            { 
                return false;
            }
            return result;
        } 

        ///  
        ///     Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. 
        ///        The hash code for ManagementBaseObjects is based on the MOF for the WbemObject that this instance is based on.  Two different ManagementBaseObject instances pointing to the same WbemObject in WMI will have the same mof and thus the same hash code.  Changing a property value of an object will change the hash code. 
        ///  
        /// 
        ///     A hash code for the current object. 
        /// 
        public override int GetHashCode() 
        {
            //            return base.GetHashCode(); 
 
            //This implementation has to match the Equals() implementation. In Equals(), we use
            //the WMI CompareTo() which compares values of properties, qualifiers etc. 
            //Probably the closest we can get is to take the MOF representation of the object and get it's hash code.
            int localHash = 0;
            try
            { 
                // GetText may throw if it cannot get a string for the mof for various reasons
                // This should be a very rare event 
                localHash = this.GetText(TextFormat.Mof).GetHashCode(); 
            }
            catch (ManagementException) 
            {
                // use the hash code of an empty string on failure to get the mof
                localHash = string.Empty.GetHashCode();
            } 
            catch (System.Runtime.InteropServices.COMException)
            { 
                // use the hash code of an empty string on failure to get the mof 
                localHash = string.Empty.GetHashCode();
            } 
            return localHash;
        }

        //***************************************************** 
        //CompareTo
        //****************************************************** 
        ///  
        ///    Compares this object to another, based on specified options.
        ///  
        /// The object to which to compare this object. 
        /// Options on how to compare the objects. 
        /// 
        ///  if the objects compared are equal 
        ///    according to the given options; otherwise, 
        ///    . 
        ///  
        public bool CompareTo(ManagementBaseObject otherObject, ComparisonSettings settings)
        { 
            if (null == otherObject)
                throw new ArgumentNullException ("otherObject");

            // 
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter. 
            // 
            // Initialize ( ) ;
            bool result = false; 

            if (null != wbemObject)
            {
                int status = (int) ManagementStatus.NoError; 

                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on 
                // its getter.
                // 
                //otherObject.Initialize ( false ) ;

                status = wbemObject.CompareTo_((int) settings, otherObject.wbemObject);
 
                if ((int)ManagementStatus.Different == status)
                    result = false; 
                else if ((int)ManagementStatus.NoError == status) 
                    result = true;
                else if ((status & 0xfffff000) == 0x80041000) 
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                else if (status < 0)
                    Marshal.ThrowExceptionForHR(status);
            } 

            return result; 
        } 

        internal string ClassName 
        {
            get
            {
                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
                // its getter. 
                // 
                // Initialize ( ) ;
                object val = null; 
                int dummy1 = 0, dummy2 = 0;
                int status = (int)ManagementStatus.NoError;

                status = wbemObject.Get_ ("__CLASS", 0, ref val, ref dummy1, ref dummy2); 

                if (status < 0) 
                { 
                    if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); 
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
 
                if (val is System.DBNull)
                    return String.Empty; 
                else 
                    return ((string) val);
            } 
        }

        private static bool _IsClass(IWbemClassObjectFreeThreaded wbemObject)
        { 
            object val = null;
            int dummy1 = 0, dummy2 = 0; 
 
            int status = wbemObject.Get_("__GENUS", 0, ref val, ref dummy1, ref dummy2);
 
            if (status < 0)
            {
                if ((status & 0xfffff000) == 0x80041000)
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); 
                else
                    Marshal.ThrowExceptionForHR(status); 
            } 

            return ((int)val == (int)tag_WBEM_GENUS_TYPE.WBEM_GENUS_CLASS); 
        }

        internal bool IsClass
        { 
            get
            { 
                // 
                // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
                // its getter. 
                //
                // Initialize ( ) ;
                return _IsClass(wbemObject);
            } 
        }
 
        ///  
        ///    Sets the value of the named property.
        ///  
        /// The name of the property to be changed.
        /// The new value for this property.
        public void SetPropertyValue (
            string propertyName, 
            object propertyValue)
        { 
            if (null == propertyName) 
                throw new ArgumentNullException ("propertyName");
 
            // Check for system properties
            if (propertyName.StartsWith ("__", StringComparison.Ordinal))
                SystemProperties[propertyName].Value = propertyValue;
            else 
                Properties[propertyName].Value = propertyValue;
        } 
 
    }//ManagementBaseObject
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK