//Constructor
        internal ManagementObjectCollection(
            ManagementScope scope,
            EnumerationOptions options,
            IEnumWbemClassObject enumWbem)
        {
            if (null != options)
            {
                this.options = (EnumerationOptions)options.Clone();
            }
            else
            {
                this.options = new EnumerationOptions();
            }

            if (null != scope)
            {
                this.scope = (ManagementScope)scope.Clone();
            }
            else
            {
                this.scope = ManagementScope._Clone(null);
            }

            this.enumWbem = enumWbem;
        }
예제 #2
0
        public void GetRelationshipClasses(ManagementOperationObserver watcher, string relationshipClass, string relationshipQualifier, string thisRole, EnumerationOptions options)
        {
            EnumerationOptions enumerationOption;

            if (this.Path == null || this.Path.Path == null || this.Path.Path.Length == 0)
            {
                throw new InvalidOperationException();
            }
            else
            {
                if (watcher != null)
                {
                    this.Initialize(true);
                    if (options != null)
                    {
                        enumerationOption = (EnumerationOptions)options.Clone();
                    }
                    else
                    {
                        enumerationOption = new EnumerationOptions();
                    }
                    EnumerationOptions enumerationOption1 = enumerationOption;
                    enumerationOption1.EnumerateDeep     = true;
                    enumerationOption1.ReturnImmediately = false;
                    if (watcher.HaveListenersForProgress)
                    {
                        enumerationOption1.SendStatus = true;
                    }
                    WmiEventSink      newSink           = watcher.GetNewSink(base.Scope, enumerationOption1.Context);
                    RelationshipQuery relationshipQuery = new RelationshipQuery(true, this.Path.Path, relationshipClass, relationshipQualifier, thisRole);
                    SecurityHandler   securityHandler   = base.Scope.GetSecurityHandler();
                    int num = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQueryAsync_(relationshipQuery.QueryLanguage, relationshipQuery.QueryString, enumerationOption1.Flags, enumerationOption1.GetContext(), newSink.Stub);
                    if (securityHandler != null)
                    {
                        securityHandler.Reset();
                    }
                    if (num < 0)
                    {
                        watcher.RemoveSink(newSink);
                        if (((long)num & (long)-4096) != (long)-2147217408)
                        {
                            Marshal.ThrowExceptionForHR(num);
                        }
                        else
                        {
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
                            return;
                        }
                    }
                    return;
                }
                else
                {
                    throw new ArgumentNullException("watcher");
                }
            }
        }
예제 #3
0
        public void GetSubclasses(ManagementOperationObserver watcher, EnumerationOptions options)
        {
            EnumerationOptions enumerationOption;

            if (watcher != null)
            {
                if (this.Path != null)
                {
                    this.Initialize(false);
                    if (options == null)
                    {
                        enumerationOption = new EnumerationOptions();
                    }
                    else
                    {
                        enumerationOption = (EnumerationOptions)options.Clone();
                    }
                    EnumerationOptions enumerationOption1 = enumerationOption;
                    enumerationOption1.EnsureLocatable   = false;
                    enumerationOption1.PrototypeOnly     = false;
                    enumerationOption1.ReturnImmediately = false;
                    if (watcher.HaveListenersForProgress)
                    {
                        enumerationOption1.SendStatus = true;
                    }
                    WmiEventSink    newSink         = watcher.GetNewSink(base.Scope, enumerationOption1.Context);
                    SecurityHandler securityHandler = base.Scope.GetSecurityHandler();
                    int             num             = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnumAsync_(base.ClassName, enumerationOption1.Flags, enumerationOption1.GetContext(), newSink.Stub);
                    if (securityHandler != null)
                    {
                        securityHandler.Reset();
                    }
                    if (num < 0)
                    {
                        watcher.RemoveSink(newSink);
                        if (((long)num & (long)-4096) != (long)-2147217408)
                        {
                            Marshal.ThrowExceptionForHR(num);
                        }
                        else
                        {
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
                            return;
                        }
                    }
                    return;
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                throw new ArgumentNullException("watcher");
            }
        }
예제 #4
0
        public ManagementObjectCollection GetRelatedClasses(string relatedClass, string relationshipClass, string relationshipQualifier, string relatedQualifier, string relatedRole, string thisRole, EnumerationOptions options)
        {
            EnumerationOptions enumerationOption;

            if (this.Path == null || this.Path.Path == null || this.Path.Path.Length == 0)
            {
                throw new InvalidOperationException();
            }
            else
            {
                this.Initialize(false);
                IEnumWbemClassObject enumWbemClassObject = null;
                if (options != null)
                {
                    enumerationOption = (EnumerationOptions)options.Clone();
                }
                else
                {
                    enumerationOption = new EnumerationOptions();
                }
                EnumerationOptions enumerationOption1 = enumerationOption;
                enumerationOption1.EnumerateDeep = true;
                RelatedObjectQuery relatedObjectQuery = new RelatedObjectQuery(true, this.Path.Path, relatedClass, relationshipClass, relatedQualifier, relationshipQualifier, relatedRole, thisRole);
                SecurityHandler    securityHandler    = null;
                int num = 0;
                try
                {
                    securityHandler = base.Scope.GetSecurityHandler();
                    num             = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQuery_(relatedObjectQuery.QueryLanguage, relatedObjectQuery.QueryString, enumerationOption1.Flags, enumerationOption1.GetContext(), ref enumWbemClassObject);
                }
                finally
                {
                    if (securityHandler != null)
                    {
                        securityHandler.Reset();
                    }
                }
                if (num < 0)
                {
                    if (((long)num & (long)-4096) != (long)-2147217408)
                    {
                        Marshal.ThrowExceptionForHR(num);
                    }
                    else
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
                    }
                }
                return(new ManagementObjectCollection(base.Scope, enumerationOption1, enumWbemClassObject));
            }
        }
예제 #5
0
        public ManagementObjectCollection GetSubclasses(EnumerationOptions options)
        {
            EnumerationOptions enumerationOption;

            if (this.Path != null)
            {
                this.Initialize(false);
                IEnumWbemClassObject enumWbemClassObject = null;
                if (options == null)
                {
                    enumerationOption = new EnumerationOptions();
                }
                else
                {
                    enumerationOption = (EnumerationOptions)options.Clone();
                }
                EnumerationOptions enumerationOption1 = enumerationOption;
                enumerationOption1.EnsureLocatable = false;
                enumerationOption1.PrototypeOnly   = false;
                SecurityHandler securityHandler = null;
                int             num             = 0;
                try
                {
                    securityHandler = base.Scope.GetSecurityHandler();
                    num             = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnum_(base.ClassName, enumerationOption1.Flags, enumerationOption1.GetContext(), ref enumWbemClassObject);
                }
                finally
                {
                    if (securityHandler != null)
                    {
                        securityHandler.Reset();
                    }
                }
                if (num < 0)
                {
                    if (((long)num & (long)-4096) != (long)-2147217408)
                    {
                        Marshal.ThrowExceptionForHR(num);
                    }
                    else
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
                    }
                }
                return(new ManagementObjectCollection(base.Scope, enumerationOption1, enumWbemClassObject));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
예제 #6
0
        //internal IWbemServices GetIWbemServices () {
        //  return scope.GetIWbemServices ();
        //}

        //internal ConnectionOptions Connection {
        //  get { return scope.Connection; }
        //}

        //Constructor
        internal ManagementObjectCollection(
            ManagementScope scope,
            EnumerationOptions options, 
            IEnumWbemClassObject enumWbem)
        {
            if (null != options)
                this.options = (EnumerationOptions) options.Clone();
            else
                this.options = new EnumerationOptions ();

            if (null != scope)
                this.scope = (ManagementScope)scope.Clone ();
            else
                this.scope = ManagementScope._Clone(null);

            this.enumWbem = enumWbem;
        }
예제 #7
0
        public void GetRelationshipClasses(ManagementOperationObserver watcher, string relationshipClass, string relationshipQualifier, string thisRole, EnumerationOptions options)
        {
            if (((this.Path == null) || (this.Path.Path == null)) || (this.Path.Path.Length == 0))
            {
                throw new InvalidOperationException();
            }
            if (watcher == null)
            {
                throw new ArgumentNullException("watcher");
            }
            this.Initialize(true);
            EnumerationOptions options2 = (options != null) ? ((EnumerationOptions)options.Clone()) : new EnumerationOptions();

            options2.EnumerateDeep     = true;
            options2.ReturnImmediately = false;
            if (watcher.HaveListenersForProgress)
            {
                options2.SendStatus = true;
            }
            WmiEventSink      newSink         = watcher.GetNewSink(base.Scope, options2.Context);
            RelationshipQuery query           = new RelationshipQuery(true, this.Path.Path, relationshipClass, relationshipQualifier, thisRole);
            SecurityHandler   securityHandler = null;
            int errorCode = 0;

            securityHandler = base.Scope.GetSecurityHandler();
            errorCode       = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQueryAsync_(query.QueryLanguage, query.QueryString, options2.Flags, options2.GetContext(), newSink.Stub);
            if (securityHandler != null)
            {
                securityHandler.Reset();
            }
            if (errorCode < 0)
            {
                watcher.RemoveSink(newSink);
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                }
                else
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
            }
        }
 public ManagementObjectSearcher(ManagementScope scope, ObjectQuery query, EnumerationOptions options)
 {
     this.scope = ManagementScope._Clone(scope);
     if (query != null)
     {
         this.query = (ObjectQuery) query.Clone();
     }
     else
     {
         this.query = new ObjectQuery();
     }
     if (options != null)
     {
         this.options = (EnumerationOptions) options.Clone();
     }
     else
     {
         this.options = new EnumerationOptions();
     }
 }
예제 #9
0
 public ManagementObjectSearcher(ManagementScope scope, ObjectQuery query, EnumerationOptions options)
 {
     this.scope = ManagementScope._Clone(scope);
     if (query != null)
     {
         this.query = (ObjectQuery)query.Clone();
     }
     else
     {
         this.query = new ObjectQuery();
     }
     if (options != null)
     {
         this.options = (EnumerationOptions)options.Clone();
     }
     else
     {
         this.options = new EnumerationOptions();
     }
 }
 internal ManagementObjectCollection(ManagementScope scope, EnumerationOptions options, IEnumWbemClassObject enumWbem)
 {
     if (options != null)
     {
         this.options = (EnumerationOptions) options.Clone();
     }
     else
     {
         this.options = new EnumerationOptions();
     }
     if (scope != null)
     {
         this.scope = scope.Clone();
     }
     else
     {
         this.scope = ManagementScope._Clone(null);
     }
     this.enumWbem = enumWbem;
 }
예제 #11
0
        public ManagementObjectCollection GetRelatedClasses(string relatedClass, string relationshipClass, string relationshipQualifier, string relatedQualifier, string relatedRole, string thisRole, EnumerationOptions options)
        {
            if (((this.Path == null) || (this.Path.Path == null)) || (this.Path.Path.Length == 0))
            {
                throw new InvalidOperationException();
            }
            this.Initialize(false);
            IEnumWbemClassObject ppEnum   = null;
            EnumerationOptions   options2 = (options != null) ? ((EnumerationOptions)options.Clone()) : new EnumerationOptions();

            options2.EnumerateDeep = true;
            RelatedObjectQuery query           = new RelatedObjectQuery(true, this.Path.Path, relatedClass, relationshipClass, relatedQualifier, relationshipQualifier, relatedRole, thisRole);
            SecurityHandler    securityHandler = null;
            int errorCode = 0;

            try
            {
                securityHandler = base.Scope.GetSecurityHandler();
                errorCode       = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQuery_(query.QueryLanguage, query.QueryString, options2.Flags, options2.GetContext(), ref ppEnum);
            }
            finally
            {
                if (securityHandler != null)
                {
                    securityHandler.Reset();
                }
            }
            if (errorCode < 0)
            {
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                }
                else
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
            }
            return(new ManagementObjectCollection(base.Scope, options2, ppEnum));
        }
예제 #12
0
		public ManagementObjectCollection GetSubclasses(EnumerationOptions options)
		{
			EnumerationOptions enumerationOption;
			if (this.Path != null)
			{
				this.Initialize(false);
				IEnumWbemClassObject enumWbemClassObject = null;
				if (options == null)
				{
					enumerationOption = new EnumerationOptions();
				}
				else
				{
					enumerationOption = (EnumerationOptions)options.Clone();
				}
				EnumerationOptions enumerationOption1 = enumerationOption;
				enumerationOption1.EnsureLocatable = false;
				enumerationOption1.PrototypeOnly = false;
				SecurityHandler securityHandler = null;
				int num = 0;
				try
				{
					securityHandler = base.Scope.GetSecurityHandler();
					num = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnum_(base.ClassName, enumerationOption1.Flags, enumerationOption1.GetContext(), ref enumWbemClassObject);
				}
				finally
				{
					if (securityHandler != null)
					{
						securityHandler.Reset();
					}
				}
				if (num < 0)
				{
					if (((long)num & (long)-4096) != (long)-2147217408)
					{
						Marshal.ThrowExceptionForHR(num);
					}
					else
					{
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
					}
				}
				return new ManagementObjectCollection(base.Scope, enumerationOption1, enumWbemClassObject);
			}
			else
			{
				throw new InvalidOperationException();
			}
		}
예제 #13
0
		public void GetSubclasses(ManagementOperationObserver watcher, EnumerationOptions options)
		{
			EnumerationOptions enumerationOption;
			if (watcher != null)
			{
				if (this.Path != null)
				{
					this.Initialize(false);
					if (options == null)
					{
						enumerationOption = new EnumerationOptions();
					}
					else
					{
						enumerationOption = (EnumerationOptions)options.Clone();
					}
					EnumerationOptions enumerationOption1 = enumerationOption;
					enumerationOption1.EnsureLocatable = false;
					enumerationOption1.PrototypeOnly = false;
					enumerationOption1.ReturnImmediately = false;
					if (watcher.HaveListenersForProgress)
					{
						enumerationOption1.SendStatus = true;
					}
					WmiEventSink newSink = watcher.GetNewSink(base.Scope, enumerationOption1.Context);
					SecurityHandler securityHandler = base.Scope.GetSecurityHandler();
					int num = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnumAsync_(base.ClassName, enumerationOption1.Flags, enumerationOption1.GetContext(), newSink.Stub);
					if (securityHandler != null)
					{
						securityHandler.Reset();
					}
					if (num < 0)
					{
						watcher.RemoveSink(newSink);
						if (((long)num & (long)-4096) != (long)-2147217408)
						{
							Marshal.ThrowExceptionForHR(num);
						}
						else
						{
							ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
							return;
						}
					}
					return;
				}
				else
				{
					throw new InvalidOperationException();
				}
			}
			else
			{
				throw new ArgumentNullException("watcher");
			}
		}
 public ManagementObjectCollection GetRelatedClasses(string relatedClass, string relationshipClass, string relationshipQualifier, string relatedQualifier, string relatedRole, string thisRole, EnumerationOptions options)
 {
     if (((this.Path == null) || (this.Path.Path == null)) || (this.Path.Path.Length == 0))
     {
         throw new InvalidOperationException();
     }
     this.Initialize(false);
     IEnumWbemClassObject ppEnum = null;
     EnumerationOptions options2 = (options != null) ? ((EnumerationOptions) options.Clone()) : new EnumerationOptions();
     options2.EnumerateDeep = true;
     RelatedObjectQuery query = new RelatedObjectQuery(true, this.Path.Path, relatedClass, relationshipClass, relatedQualifier, relationshipQualifier, relatedRole, thisRole);
     SecurityHandler securityHandler = null;
     int errorCode = 0;
     try
     {
         securityHandler = base.Scope.GetSecurityHandler();
         errorCode = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQuery_(query.QueryLanguage, query.QueryString, options2.Flags, options2.GetContext(), ref ppEnum);
     }
     finally
     {
         if (securityHandler != null)
         {
             securityHandler.Reset();
         }
     }
     if (errorCode < 0)
     {
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
         }
         else
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
     return new ManagementObjectCollection(base.Scope, options2, ppEnum);
 }
 public void GetRelationshipClasses(ManagementOperationObserver watcher, string relationshipClass, string relationshipQualifier, string thisRole, EnumerationOptions options)
 {
     if (((this.Path == null) || (this.Path.Path == null)) || (this.Path.Path.Length == 0))
     {
         throw new InvalidOperationException();
     }
     if (watcher == null)
     {
         throw new ArgumentNullException("watcher");
     }
     this.Initialize(true);
     EnumerationOptions options2 = (options != null) ? ((EnumerationOptions) options.Clone()) : new EnumerationOptions();
     options2.EnumerateDeep = true;
     options2.ReturnImmediately = false;
     if (watcher.HaveListenersForProgress)
     {
         options2.SendStatus = true;
     }
     WmiEventSink newSink = watcher.GetNewSink(base.Scope, options2.Context);
     RelationshipQuery query = new RelationshipQuery(true, this.Path.Path, relationshipClass, relationshipQualifier, thisRole);
     SecurityHandler securityHandler = null;
     int errorCode = 0;
     securityHandler = base.Scope.GetSecurityHandler();
     errorCode = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQueryAsync_(query.QueryLanguage, query.QueryString, options2.Flags, options2.GetContext(), newSink.Stub);
     if (securityHandler != null)
     {
         securityHandler.Reset();
     }
     if (errorCode < 0)
     {
         watcher.RemoveSink(newSink);
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
         }
         else
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
 }
		/// <summary>
		///    <para> Retrieves classes related to the WMI class based on the specified 
		///       options.</para>
		/// </summary>
		/// <param name=' relatedClass'><para>The class from which resulting classes have to be derived.</para></param>
		/// <param name=' relationshipClass'> The relationship type which resulting classes must have with the source class.</param>
		/// <param name=' relationshipQualifier'>This qualifier must be present on the relationship.</param>
		/// <param name=' relatedQualifier'>This qualifier must be present on the resulting classes.</param>
		/// <param name=' relatedRole'>The resulting classes must have this role in the relationship.</param>
		/// <param name=' thisRole'>The source class must have this role in the relationship.</param>
		/// <param name=' options'>The options for retrieving the resulting classes.</param>
		/// <returns>
		///    <para>A collection of classes related to
		///       this class.</para>
		/// </returns>
		public ManagementObjectCollection GetRelatedClasses(
											string relatedClass,
											string relationshipClass,
											string relationshipQualifier,
											string relatedQualifier,
											string relatedRole,
											string thisRole,
											EnumerationOptions options)
		{
			if ((null == Path) || (null == Path.Path) || (0 == Path.Path.Length))
				throw new InvalidOperationException();

			Initialize ( false ) ;

			IEnumWbemClassObject enumWbem = null;

			EnumerationOptions o = (null != options) ? (EnumerationOptions)options.Clone() : new EnumerationOptions();
			//Ensure EnumerateDeep flag bit is turned off as it's invalid for queries
			o.EnumerateDeep = true;

			RelatedObjectQuery q = new RelatedObjectQuery(true,	Path.Path, 
															relatedClass,
															relationshipClass, 
															relatedQualifier,
															relationshipQualifier, 
															relatedRole, thisRole);

			SecurityHandler securityHandler = null;
			int status						= (int)ManagementStatus.NoError;

    		try
			{
				securityHandler = Scope.GetSecurityHandler();
				status = scope.GetSecuredIWbemServicesHandler(Scope.GetIWbemServices() ).ExecQuery_(
					q.QueryLanguage, 
					q.QueryString, 
					o.Flags, 
					o.GetContext(), 
					ref enumWbem);

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

			//Create collection object
			return new ManagementObjectCollection(Scope, o, enumWbem);
		}
예제 #17
0
        public void GetSubclasses(ManagementOperationObserver watcher, EnumerationOptions options)
        {
            if (watcher == null)
            {
                throw new ArgumentNullException("watcher");
            }
            if (this.Path == null)
            {
                throw new InvalidOperationException();
            }
            this.Initialize(false);
            EnumerationOptions options2 = (options == null) ? new EnumerationOptions() : ((EnumerationOptions)options.Clone());

            options2.EnsureLocatable   = false;
            options2.PrototypeOnly     = false;
            options2.ReturnImmediately = false;
            if (watcher.HaveListenersForProgress)
            {
                options2.SendStatus = true;
            }
            WmiEventSink    newSink         = watcher.GetNewSink(base.Scope, options2.Context);
            SecurityHandler securityHandler = null;
            int             errorCode       = 0;

            securityHandler = base.Scope.GetSecurityHandler();
            errorCode       = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnumAsync_(base.ClassName, options2.Flags, options2.GetContext(), newSink.Stub);
            if (securityHandler != null)
            {
                securityHandler.Reset();
            }
            if (errorCode < 0)
            {
                watcher.RemoveSink(newSink);
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                }
                else
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
            }
        }
예제 #18
0
        public ManagementObjectCollection GetSubclasses(EnumerationOptions options)
        {
            if (this.Path == null)
            {
                throw new InvalidOperationException();
            }
            this.Initialize(false);
            IEnumWbemClassObject ppEnum   = null;
            EnumerationOptions   options2 = (options == null) ? new EnumerationOptions() : ((EnumerationOptions)options.Clone());

            options2.EnsureLocatable = false;
            options2.PrototypeOnly   = false;
            SecurityHandler securityHandler = null;
            int             errorCode       = 0;

            try
            {
                securityHandler = base.Scope.GetSecurityHandler();
                errorCode       = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnum_(base.ClassName, options2.Flags, options2.GetContext(), ref ppEnum);
            }
            finally
            {
                if (securityHandler != null)
                {
                    securityHandler.Reset();
                }
            }
            if (errorCode < 0)
            {
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                }
                else
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
            }
            return(new ManagementObjectCollection(base.Scope, options2, ppEnum));
        }
 public void GetSubclasses(ManagementOperationObserver watcher, EnumerationOptions options)
 {
     if (watcher == null)
     {
         throw new ArgumentNullException("watcher");
     }
     if (this.Path == null)
     {
         throw new InvalidOperationException();
     }
     this.Initialize(false);
     EnumerationOptions options2 = (options == null) ? new EnumerationOptions() : ((EnumerationOptions) options.Clone());
     options2.EnsureLocatable = false;
     options2.PrototypeOnly = false;
     options2.ReturnImmediately = false;
     if (watcher.HaveListenersForProgress)
     {
         options2.SendStatus = true;
     }
     WmiEventSink newSink = watcher.GetNewSink(base.Scope, options2.Context);
     SecurityHandler securityHandler = null;
     int errorCode = 0;
     securityHandler = base.Scope.GetSecurityHandler();
     errorCode = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnumAsync_(base.ClassName, options2.Flags, options2.GetContext(), newSink.Stub);
     if (securityHandler != null)
     {
         securityHandler.Reset();
     }
     if (errorCode < 0)
     {
         watcher.RemoveSink(newSink);
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
         }
         else
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
 }
예제 #20
0
		public ManagementObjectCollection GetRelatedClasses(string relatedClass, string relationshipClass, string relationshipQualifier, string relatedQualifier, string relatedRole, string thisRole, EnumerationOptions options)
		{
			EnumerationOptions enumerationOption;
			if (this.Path == null || this.Path.Path == null || this.Path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				this.Initialize(false);
				IEnumWbemClassObject enumWbemClassObject = null;
				if (options != null)
				{
					enumerationOption = (EnumerationOptions)options.Clone();
				}
				else
				{
					enumerationOption = new EnumerationOptions();
				}
				EnumerationOptions enumerationOption1 = enumerationOption;
				enumerationOption1.EnumerateDeep = true;
				RelatedObjectQuery relatedObjectQuery = new RelatedObjectQuery(true, this.Path.Path, relatedClass, relationshipClass, relatedQualifier, relationshipQualifier, relatedRole, thisRole);
				SecurityHandler securityHandler = null;
				int num = 0;
				try
				{
					securityHandler = base.Scope.GetSecurityHandler();
					num = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQuery_(relatedObjectQuery.QueryLanguage, relatedObjectQuery.QueryString, enumerationOption1.Flags, enumerationOption1.GetContext(), ref enumWbemClassObject);
				}
				finally
				{
					if (securityHandler != null)
					{
						securityHandler.Reset();
					}
				}
				if (num < 0)
				{
					if (((long)num & (long)-4096) != (long)-2147217408)
					{
						Marshal.ThrowExceptionForHR(num);
					}
					else
					{
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
					}
				}
				return new ManagementObjectCollection(base.Scope, enumerationOption1, enumWbemClassObject);
			}
		}
		/// <summary>
		///    <para>Retrieves all classes derived from this class, asynchronously, using the specified 
		///       options.</para>
		/// </summary>
		/// <param name='watcher'>The object to handle the asynchronous operation's progress. </param>
		/// <param name='options'>The specified additional options to use in the derived class retrieval.</param>
		public void GetSubclasses(ManagementOperationObserver watcher,
										EnumerationOptions options) 
		{ 				
			if (null == watcher)
				throw new ArgumentNullException("watcher");
			
			if (null == Path)
				throw new InvalidOperationException();

			Initialize ( false ) ;

			EnumerationOptions o = (null == options) ? new EnumerationOptions() : 
									  (EnumerationOptions)options.Clone();

			//Need to make sure that we're not passing invalid flags to enumeration APIs.
			//The only flags in EnumerationOptions not valid for enumerations are EnsureLocatable & PrototypeOnly.
			o.EnsureLocatable = false; o.PrototypeOnly = false;

			// Ensure we switch off ReturnImmediately as this is invalid for async calls
			o.ReturnImmediately = false;

			// If someone has registered for progress, make sure we flag it
			if (watcher.HaveListenersForProgress)
				o.SendStatus = true;

			WmiEventSink sink = watcher.GetNewSink(Scope, o.Context);

			SecurityHandler securityHandler = null;
			int status						= (int)ManagementStatus.NoError;

			securityHandler = Scope.GetSecurityHandler();

                    status = scope.GetSecuredIWbemServicesHandler(Scope.GetIWbemServices() ).CreateClassEnumAsync_(ClassName,
				o.Flags,
				o.GetContext(),
				sink.Stub);


			if (securityHandler != null)
				securityHandler.Reset();

			if (status < 0)
			{
				watcher.RemoveSink(sink);
				if ((status & 0xfffff000) == 0x80041000)
					ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
				else
					Marshal.ThrowExceptionForHR(status);
			}
		}
		/// <summary>
		///    <para>Retrieves the subclasses of the class using the specified
		///       options.</para>
		/// </summary>
		/// <param name='options'>The specified additional options for retrieving subclasses of the class.</param>
		/// <returns>
		/// <para>A collection of the <see cref='System.Management.ManagementObject'/> objects
		///    representing the subclasses of the WMI class, according to the specified
		///    options.</para>
		/// </returns>
		/// <example>
		///    <code lang='C#'>EnumerationOptions opt = new EnumerationOptions();
		///    
		/// //Causes return of deep subclasses as opposed to only immediate ones.
		/// opt.enumerateDeep = true;  
		///   
		/// ManagementObjectCollection c = (new
		///       ManagementClass("Win32_Share")).GetSubclasses(opt);
		///    </code>
		///    <code lang='VB'>Dim opt As New EnumerationOptions()
		/// 
		/// 'Causes return of deep subclasses as opposed to only immediate ones.
		/// opt.enumerateDeep = true
		/// 
		/// Dim cls As New ManagementClass("Win32_Share")
		/// Dim c As ManagementObjectCollection
		/// 
		/// c = cls.GetSubClasses(opt)
		///    </code>
		/// </example>
		public ManagementObjectCollection GetSubclasses(EnumerationOptions options) 
		{ 
			if (null == Path)
				throw new InvalidOperationException();

			Initialize ( false ) ;
			IEnumWbemClassObject enumWbem = null;

			EnumerationOptions o = (null == options) ? new EnumerationOptions() : (EnumerationOptions)options.Clone();
			//Need to make sure that we're not passing invalid flags to enumeration APIs.
			//The only flags in EnumerationOptions not valid for enumerations are EnsureLocatable & PrototypeOnly.
			o.EnsureLocatable = false; o.PrototypeOnly = false;

			SecurityHandler securityHandler = null;
			int status						= (int)ManagementStatus.NoError;

			try
			{
				securityHandler = Scope.GetSecurityHandler();
                            status = scope.GetSecuredIWbemServicesHandler( Scope.GetIWbemServices() ).CreateClassEnum_(ClassName, 
					o.Flags, 
					o.GetContext(),
					ref enumWbem);
			}
			finally
			{
				if (securityHandler != null)
					securityHandler.Reset();
			}

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

			return new ManagementObjectCollection(Scope, o, enumWbem);
		}
		/// <summary>
		///    <para>Retrieves relationship classes that relate the class according to the specified 
		///       options, asynchronously.</para>
		/// </summary>
		/// <param name='watcher'>The handler for progress and results of the asynchronous operation.</param>
		/// <param name='relationshipClass'><para>The class from which all resulting relationship classes must derive.</para></param>
		/// <param name=' relationshipQualifier'>The qualifier which the resulting relationship classes must have.</param>
		/// <param name=' thisRole'>The role which the source class must have in the resulting relationship classes.</param>
		/// <param name=' options'> The options for retrieving the results.</param>
		/// <returns>
		///    <para>A collection of association classes
		///       relating this class to others, according to the given options.</para>
		/// </returns>
		public void GetRelationshipClasses(
			ManagementOperationObserver watcher, 
			string relationshipClass,
			string relationshipQualifier,
			string thisRole,
			EnumerationOptions options)
		{
			if ((null == Path) || (null == Path.Path) || (0 == Path.Path.Length))
				throw new InvalidOperationException();
			if (null == watcher)
				throw new ArgumentNullException("watcher");
			else
			{
				Initialize ( true ) ;
			
				EnumerationOptions o = 
						(null != options) ? (EnumerationOptions)options.Clone() : new EnumerationOptions();

				//Ensure EnumerateDeep flag is turned off as it's invalid for queries
				o.EnumerateDeep = true;

				// Ensure we switch off ReturnImmediately as this is invalid for async calls
				o.ReturnImmediately = false;

				// If someone has registered for progress, make sure we flag it
				if (watcher.HaveListenersForProgress)
					o.SendStatus = true;
				
				WmiEventSink sink = watcher.GetNewSink(Scope, o.Context);

				RelationshipQuery q = new RelationshipQuery(true, Path.Path, relationshipClass,
						relationshipQualifier, thisRole);

				SecurityHandler securityHandler = null;
				int status						= (int)ManagementStatus.NoError;

				securityHandler = Scope.GetSecurityHandler();

                            status = scope.GetSecuredIWbemServicesHandler(Scope.GetIWbemServices()).ExecQueryAsync_(
						q.QueryLanguage, 
						q.QueryString, 
						o.Flags, 
						o.GetContext(), 
						sink.Stub);


				if (securityHandler != null)
					securityHandler.Reset();

				if (status < 0)
				{
					watcher.RemoveSink(sink);
					if ((status & 0xfffff000) == 0x80041000)
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
					else
						Marshal.ThrowExceptionForHR(status);
				}
			}
		}
예제 #24
0
        //********************************************
        //Get()
        //********************************************
        /// <overload>
        ///    Invokes the specified WMI query and returns the resulting collection.
        /// </overload>
        /// <summary>
        ///    <para>Invokes the specified WMI query and returns the
        ///       resulting collection.</para>
        /// </summary>
        /// <returns>
        /// <para>A <see cref='System.Management.ManagementObjectCollection'/> containing the objects that match the
        ///    specified query.</para>
        /// </returns>
        public ManagementObjectCollection Get()
        {
            Initialize();
            IEnumWbemClassObject ew = null;
            SecurityHandler      securityHandler = scope.GetSecurityHandler();
            EnumerationOptions   enumOptions     = (EnumerationOptions)options.Clone();

            int status = (int)ManagementStatus.NoError;

            try
            {
                //If this is a simple SelectQuery (className only), and the enumerateDeep is set, we have
                //to find out whether this is a class enumeration or instance enumeration and call CreateInstanceEnum/
                //CreateClassEnum appropriately, because with ExecQuery we can't do a deep enumeration.
                if ((query.GetType() == typeof(SelectQuery)) &&
                    (((SelectQuery)query).Condition == null) &&
                    (((SelectQuery)query).SelectedProperties == null) &&
                    (options.EnumerateDeep == true))
                {
                    //Need to make sure that we're not passing invalid flags to enumeration APIs.
                    //The only flags not valid for enumerations are EnsureLocatable & PrototypeOnly.
                    enumOptions.EnsureLocatable = false; enumOptions.PrototypeOnly = false;

                    if (((SelectQuery)query).IsSchemaQuery == false) //deep instance enumeration
                    {
                        status = scope.GetSecuredIWbemServicesHandler(scope.GetIWbemServices()).CreateInstanceEnum_(
                            ((SelectQuery)query).ClassName,
                            enumOptions.Flags,
                            enumOptions.GetContext(),
                            ref ew);
                    }
                    else //deep class enumeration
                    {
                        status = scope.GetSecuredIWbemServicesHandler(scope.GetIWbemServices()).CreateClassEnum_(((SelectQuery)query).ClassName,
                                                                                                                 enumOptions.Flags,
                                                                                                                 enumOptions.GetContext(),
                                                                                                                 ref ew);
                    }
                }
                else //we can use ExecQuery
                {
                    //Make sure the EnumerateDeep flag bit is turned off because it's invalid for queries
                    enumOptions.EnumerateDeep = true;
                    status = scope.GetSecuredIWbemServicesHandler(scope.GetIWbemServices()).ExecQuery_(
                        query.QueryLanguage,
                        query.QueryString,
                        enumOptions.Flags,
                        enumOptions.GetContext(),
                        ref ew);
                }
            }
            catch (COMException e)
            {
                ManagementException.ThrowWithExtendedInfo(e);
            }
            finally
            {
                securityHandler.Reset();
            }

            if ((status & 0xfffff000) == 0x80041000)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
            }
            else if ((status & 0x80000000) != 0)
            {
                Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f());
            }

            //Create a new collection object for the results

            return(new ManagementObjectCollection(scope, options, ew));
        }//Get()
 public ManagementObjectCollection GetSubclasses(EnumerationOptions options)
 {
     if (this.Path == null)
     {
         throw new InvalidOperationException();
     }
     this.Initialize(false);
     IEnumWbemClassObject ppEnum = null;
     EnumerationOptions options2 = (options == null) ? new EnumerationOptions() : ((EnumerationOptions) options.Clone());
     options2.EnsureLocatable = false;
     options2.PrototypeOnly = false;
     SecurityHandler securityHandler = null;
     int errorCode = 0;
     try
     {
         securityHandler = base.Scope.GetSecurityHandler();
         errorCode = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnum_(base.ClassName, options2.Flags, options2.GetContext(), ref ppEnum);
     }
     finally
     {
         if (securityHandler != null)
         {
             securityHandler.Reset();
         }
     }
     if (errorCode < 0)
     {
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
         }
         else
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
     return new ManagementObjectCollection(base.Scope, options2, ppEnum);
 }
예제 #26
0
		public void GetRelated(ManagementOperationObserver watcher, string relatedClass, string relationshipClass, string relationshipQualifier, string relatedQualifier, string relatedRole, string thisRole, bool classDefinitionsOnly, EnumerationOptions options)
		{
			EnumerationOptions enumerationOption;
			if (this.path == null || this.path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				this.Initialize(true);
				if (watcher != null)
				{
					if (options != null)
					{
						enumerationOption = (EnumerationOptions)options.Clone();
					}
					else
					{
						enumerationOption = new EnumerationOptions();
					}
					EnumerationOptions enumerationOption1 = enumerationOption;
					enumerationOption1.ReturnImmediately = false;
					if (watcher.HaveListenersForProgress)
					{
						enumerationOption1.SendStatus = true;
					}
					WmiEventSink newSink = watcher.GetNewSink(this.scope, enumerationOption1.Context);
					RelatedObjectQuery relatedObjectQuery = new RelatedObjectQuery(this.path.Path, relatedClass, relationshipClass, relationshipQualifier, relatedQualifier, relatedRole, thisRole, classDefinitionsOnly);
					enumerationOption1.EnumerateDeep = true;
					SecurityHandler securityHandler = this.scope.GetSecurityHandler();
					int num = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).ExecQueryAsync_(relatedObjectQuery.QueryLanguage, relatedObjectQuery.QueryString, enumerationOption1.Flags, enumerationOption1.GetContext(), newSink.Stub);
					securityHandler.Reset();
					if (num < 0)
					{
						watcher.RemoveSink(newSink);
						if (((long)num & (long)-4096) != (long)-2147217408)
						{
							Marshal.ThrowExceptionForHR(num);
						}
						else
						{
							ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
							return;
						}
					}
					return;
				}
				else
				{
					throw new ArgumentNullException("watcher");
				}
			}
		}