Exemple #1
0
        public void Get(ManagementOperationObserver watcher)
        {
            if (watcher == null)
            {
                throw new ArgumentNullException("watcher");
            }
            this.Initialize();
            IWbemServices      iWbemServices = this.scope.GetIWbemServices();
            EnumerationOptions options       = (EnumerationOptions)this.options.Clone();

            options.ReturnImmediately = false;
            if (watcher.HaveListenersForProgress)
            {
                options.SendStatus = true;
            }
            WmiEventSink    newSink         = watcher.GetNewSink(this.scope, options.Context);
            SecurityHandler securityHandler = this.scope.GetSecurityHandler();
            int             errorCode       = 0;

            try
            {
                if (((this.query.GetType() == typeof(SelectQuery)) && (((SelectQuery)this.query).Condition == null)) && ((((SelectQuery)this.query).SelectedProperties == null) && this.options.EnumerateDeep))
                {
                    options.EnsureLocatable = false;
                    options.PrototypeOnly   = false;
                    if (!((SelectQuery)this.query).IsSchemaQuery)
                    {
                        errorCode = this.scope.GetSecuredIWbemServicesHandler(iWbemServices).CreateInstanceEnumAsync_(((SelectQuery)this.query).ClassName, options.Flags, options.GetContext(), newSink.Stub);
                    }
                    else
                    {
                        errorCode = this.scope.GetSecuredIWbemServicesHandler(iWbemServices).CreateClassEnumAsync_(((SelectQuery)this.query).ClassName, options.Flags, options.GetContext(), newSink.Stub);
                    }
                }
                else
                {
                    options.EnumerateDeep = true;
                    errorCode             = this.scope.GetSecuredIWbemServicesHandler(iWbemServices).ExecQueryAsync_(this.query.QueryLanguage, this.query.QueryString, options.Flags, options.GetContext(), newSink.Stub);
                }
            }
            catch (COMException exception)
            {
                watcher.RemoveSink(newSink);
                ManagementException.ThrowWithExtendedInfo(exception);
            }
            finally
            {
                securityHandler.Reset();
            }
            if ((errorCode & 0xfffff000L) == 0x80041000L)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
            }
            else if ((errorCode & 0x80000000L) != 0L)
            {
                Marshal.ThrowExceptionForHR(errorCode);
            }
        }
Exemple #2
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");
            }
        }
Exemple #3
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");
                }
            }
        }
Exemple #4
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);
                }
            }
        }
Exemple #5
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);
                }
            }
        }
        }//Get()


        //********************************************
        //Get() asynchronous
        //********************************************
        /// <summary>
        ///    <para>Invokes the WMI query, asynchronously, and binds to a watcher to deliver the results.</para>
        /// </summary>
        /// <param name='watcher'>The watcher that raises events triggered by the operation. </param>
        public void Get(ManagementOperationObserver watcher)
        {
            if (null == watcher)
                throw new ArgumentNullException ("watcher");

            Initialize ();
            IWbemServices wbemServices = scope.GetIWbemServices ();
            
            EnumerationOptions enumOptions = (EnumerationOptions)options.Clone();
            // Ensure we switch off ReturnImmediately as this is invalid for async calls
            enumOptions.ReturnImmediately = false;
            // If someone has registered for progress, make sure we flag it
            if (watcher.HaveListenersForProgress)
                enumOptions.SendStatus = true;

            WmiEventSink sink = watcher.GetNewSink (scope, enumOptions.Context);
            SecurityHandler securityHandler = scope.GetSecurityHandler();

            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( wbemServices ).CreateInstanceEnumAsync_(((SelectQuery)query).ClassName, 
                            enumOptions.Flags, 
                            enumOptions.GetContext(), 
                            sink.Stub);
                    }
                    else    
                    {
                        status = scope.GetSecuredIWbemServicesHandler( wbemServices ).CreateClassEnumAsync_(((SelectQuery)query).ClassName, 
                            enumOptions.Flags, 
                            enumOptions.GetContext(), 
                            sink.Stub);
                    }
                }
                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( wbemServices ).ExecQueryAsync_(
                        query.QueryLanguage, 
                        query.QueryString, 
                        enumOptions.Flags, 
                        enumOptions.GetContext(), 
                        sink.Stub);
                }

            } 
            catch (COMException e) 
            {
                // 
                watcher.RemoveSink (sink);
                ManagementException.ThrowWithExtendedInfo (e);
            } 
            finally 
            {
                securityHandler.Reset();
            }

            if ((status & 0xfffff000) == 0x80041000)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
            }
            else if ((status & 0x80000000) != 0)
            {
                Marshal.ThrowExceptionForHR(status);
            }
        }
        /// <summary>
        ///    <para>Deletes the object.</para>
        /// </summary>
        /// <param name='watcher'>The object that will receive the results of the operation.</param>
        /// <param name='options'>The options for how to delete the object.</param>
        public void Delete(ManagementOperationObserver watcher, DeleteOptions options)
        {
            if ((null == path) || (path.Path.Length==0))
                throw new InvalidOperationException();
            else if (null == watcher)
                throw new ArgumentNullException("watcher");
            else
            {
                Initialize ( false ) ;
                DeleteOptions o = (null != options) ? (DeleteOptions) options.Clone() : new DeleteOptions();

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

                IWbemServices wbemServices = scope.GetIWbemServices();
                WmiEventSink sink = watcher.GetNewSink(scope, o.Context);

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

                securityHandler = scope.GetSecurityHandler();

                if (IsClass)
                {
                    status = scope.GetSecuredIWbemServicesHandler( wbemServices ).DeleteClassAsync_(path.RelativePath, 
                        o.Flags, 
                        o.GetContext(),
                        sink.Stub);
                }
                else
                {
                    status = scope.GetSecuredIWbemServicesHandler( wbemServices ).DeleteInstanceAsync_(path.RelativePath, 
                        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);
                }
            }
        }
 public void Get(ManagementOperationObserver watcher)
 {
     if (watcher == null)
     {
         throw new ArgumentNullException("watcher");
     }
     this.Initialize();
     IWbemServices iWbemServices = this.scope.GetIWbemServices();
     EnumerationOptions options = (EnumerationOptions) this.options.Clone();
     options.ReturnImmediately = false;
     if (watcher.HaveListenersForProgress)
     {
         options.SendStatus = true;
     }
     WmiEventSink newSink = watcher.GetNewSink(this.scope, options.Context);
     SecurityHandler securityHandler = this.scope.GetSecurityHandler();
     int errorCode = 0;
     try
     {
         if (((this.query.GetType() == typeof(SelectQuery)) && (((SelectQuery) this.query).Condition == null)) && ((((SelectQuery) this.query).SelectedProperties == null) && this.options.EnumerateDeep))
         {
             options.EnsureLocatable = false;
             options.PrototypeOnly = false;
             if (!((SelectQuery) this.query).IsSchemaQuery)
             {
                 errorCode = this.scope.GetSecuredIWbemServicesHandler(iWbemServices).CreateInstanceEnumAsync_(((SelectQuery) this.query).ClassName, options.Flags, options.GetContext(), newSink.Stub);
             }
             else
             {
                 errorCode = this.scope.GetSecuredIWbemServicesHandler(iWbemServices).CreateClassEnumAsync_(((SelectQuery) this.query).ClassName, options.Flags, options.GetContext(), newSink.Stub);
             }
         }
         else
         {
             options.EnumerateDeep = true;
             errorCode = this.scope.GetSecuredIWbemServicesHandler(iWbemServices).ExecQueryAsync_(this.query.QueryLanguage, this.query.QueryString, options.Flags, options.GetContext(), newSink.Stub);
         }
     }
     catch (COMException exception)
     {
         watcher.RemoveSink(newSink);
         ManagementException.ThrowWithExtendedInfo(exception);
     }
     finally
     {
         securityHandler.Reset();
     }
     if ((errorCode & 0xfffff000L) == 0x80041000L)
     {
         ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
     }
     else if ((errorCode & 0x80000000L) != 0L)
     {
         Marshal.ThrowExceptionForHR(errorCode);
     }
 }
		public void Get(ManagementOperationObserver watcher)
		{
			if (watcher != null)
			{
				this.Initialize();
				IWbemServices wbemServices = this.scope.GetIWbemServices();
				EnumerationOptions enumerationOption = (EnumerationOptions)this.options.Clone();
				enumerationOption.ReturnImmediately = false;
				if (watcher.HaveListenersForProgress)
				{
					enumerationOption.SendStatus = true;
				}
				WmiEventSink newSink = watcher.GetNewSink(this.scope, enumerationOption.Context);
				SecurityHandler securityHandler = this.scope.GetSecurityHandler();
				int num = 0;
				try
				{
					try
					{
						if (!(this.query.GetType() == typeof(SelectQuery)) || ((SelectQuery)this.query).Condition != null || ((SelectQuery)this.query).SelectedProperties != null || !this.options.EnumerateDeep)
						{
							enumerationOption.EnumerateDeep = true;
							num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).ExecQueryAsync_(this.query.QueryLanguage, this.query.QueryString, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
						}
						else
						{
							enumerationOption.EnsureLocatable = false;
							enumerationOption.PrototypeOnly = false;
							if (((SelectQuery)this.query).IsSchemaQuery)
							{
								num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).CreateClassEnumAsync_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
							}
							else
							{
								num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).CreateInstanceEnumAsync_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
							}
						}
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						watcher.RemoveSink(newSink);
						ManagementException.ThrowWithExtendedInfo(cOMException);
					}
				}
				finally
				{
					securityHandler.Reset();
				}
				if (((long)num & (long)-4096) != (long)-2147217408)
				{
					if (((long)num & (long)-2147483648) != (long)0)
					{
						Marshal.ThrowExceptionForHR(num);
					}
					return;
				}
				else
				{
					ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
					return;
				}
			}
			else
			{
				throw new ArgumentNullException("watcher");
			}
		}
Exemple #10
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");
				}
			}
		}
Exemple #11
0
		public void Delete(ManagementOperationObserver watcher, DeleteOptions options)
		{
			int num;
			DeleteOptions deleteOption;
			if (this.path == null || this.path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				if (watcher != null)
				{
					this.Initialize(false);
					if (options != null)
					{
						deleteOption = (DeleteOptions)options.Clone();
					}
					else
					{
						deleteOption = new DeleteOptions();
					}
					DeleteOptions deleteOption1 = deleteOption;
					if (watcher.HaveListenersForProgress)
					{
						deleteOption1.SendStatus = true;
					}
					IWbemServices wbemServices = this.scope.GetIWbemServices();
					WmiEventSink newSink = watcher.GetNewSink(this.scope, deleteOption1.Context);
					SecurityHandler securityHandler = this.scope.GetSecurityHandler();
					if (!base.IsClass)
					{
						num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).DeleteInstanceAsync_(this.path.RelativePath, deleteOption1.Flags, deleteOption1.GetContext(), newSink.Stub);
					}
					else
					{
						num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).DeleteClassAsync_(this.path.RelativePath, deleteOption1.Flags, deleteOption1.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");
				}
			}
		}
Exemple #12
0
		public void InvokeMethod(ManagementOperationObserver watcher, string methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
		{
			InvokeMethodOptions invokeMethodOption;
			if (this.path == null || this.path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				if (watcher != null)
				{
					if (methodName != null)
					{
						this.Initialize(false);
						if (options != null)
						{
							invokeMethodOption = (InvokeMethodOptions)options.Clone();
						}
						else
						{
							invokeMethodOption = new InvokeMethodOptions();
						}
						InvokeMethodOptions invokeMethodOption1 = invokeMethodOption;
						if (watcher.HaveListenersForProgress)
						{
							invokeMethodOption1.SendStatus = true;
						}
						WmiEventSink newSink = watcher.GetNewSink(this.scope, invokeMethodOption1.Context);
						SecurityHandler securityHandler = this.scope.GetSecurityHandler();
						IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = null;
						if (inParameters != null)
						{
							wbemClassObjectFreeThreaded = inParameters.wbemObject;
						}
						int num = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).ExecMethodAsync_(this.path.RelativePath, methodName, invokeMethodOption1.Flags, invokeMethodOption1.GetContext(), wbemClassObjectFreeThreaded, 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("methodName");
					}
				}
				else
				{
					throw new ArgumentNullException("watcher");
				}
			}
		}
 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);
         }
     }
 }
 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>Invokes a method on the object, asynchronously.</para>
        /// </summary>
        /// <param name='watcher'>A <see cref='System.Management.ManagementOperationObserver'/> used to handle the asynchronous execution's progress and results.</param>
        /// <param name=' methodName'>The name of the method to be executed.</param>
        /// <param name=' inParameters'><para>A <see cref='System.Management.ManagementBaseObject'/> containing the input parameters for the method.</para></param>
        /// <param name=' options'>An <see cref='System.Management.InvokeMethodOptions'/> containing additional options used to execute the method.</param>
        /// <remarks>
        ///    <para>The method invokes the specified method execution and then 
        ///       returns. Progress and results are reported through events on the <see cref='System.Management.ManagementOperationObserver'/>.</para>
        /// </remarks>
        public void InvokeMethod(
            ManagementOperationObserver watcher, 
            string methodName, 
            ManagementBaseObject inParameters, 
            InvokeMethodOptions options)
        {
            if ((null == path) || (path.Path.Length==0))
                throw new InvalidOperationException();
            else if (null == watcher)
                throw new ArgumentNullException("watcher");
            else if (null == methodName)
                throw new ArgumentNullException("methodName");
            else
            {
                Initialize ( false ) ;
                InvokeMethodOptions o = (null != options) ? 
                    (InvokeMethodOptions) options.Clone() : new InvokeMethodOptions();

                // 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();

                IWbemClassObjectFreeThreaded inParams = null;

                if (null != inParameters)
                    inParams = inParameters.wbemObject;

                status = scope.GetSecuredIWbemServicesHandler( scope.GetIWbemServices() ).ExecMethodAsync_(
                    path.RelativePath, 
                    methodName,
                    o.Flags, 
                    o.GetContext(),
                    inParams,
                    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 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);
				}
			}
		}
Exemple #17
0
        }//Get()

        //********************************************
        //Get() asynchronous
        //********************************************
        /// <summary>
        ///    <para>Invokes the WMI query, asynchronously, and binds to a watcher to deliver the results.</para>
        /// </summary>
        /// <param name='watcher'>The watcher that raises events triggered by the operation. </param>
        public void Get(ManagementOperationObserver watcher)
        {
            if (null == watcher)
            {
                throw new ArgumentNullException(nameof(watcher));
            }

            Initialize();
            IWbemServices wbemServices = scope.GetIWbemServices();

            EnumerationOptions enumOptions = (EnumerationOptions)options.Clone();

            // Ensure we switch off ReturnImmediately as this is invalid for async calls
            enumOptions.ReturnImmediately = false;
            // If someone has registered for progress, make sure we flag it
            if (watcher.HaveListenersForProgress)
            {
                enumOptions.SendStatus = true;
            }

            WmiEventSink    sink            = watcher.GetNewSink(scope, enumOptions.Context);
            SecurityHandler securityHandler = scope.GetSecurityHandler();

            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(wbemServices).CreateInstanceEnumAsync_(((SelectQuery)query).ClassName,
                                                                                                             enumOptions.Flags,
                                                                                                             enumOptions.GetContext(),
                                                                                                             sink.Stub);
                    }
                    else
                    {
                        status = scope.GetSecuredIWbemServicesHandler(wbemServices).CreateClassEnumAsync_(((SelectQuery)query).ClassName,
                                                                                                          enumOptions.Flags,
                                                                                                          enumOptions.GetContext(),
                                                                                                          sink.Stub);
                    }
                }
                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(wbemServices).ExecQueryAsync_(
                        query.QueryLanguage,
                        query.QueryString,
                        enumOptions.Flags,
                        enumOptions.GetContext(),
                        sink.Stub);
                }
            }
            catch (COMException e)
            {
                watcher.RemoveSink(sink);
                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());
            }
        }
		/// <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);
			}
		}
 public void Get(ManagementOperationObserver watcher)
 {
     if (watcher != null)
     {
         this.Initialize();
         IWbemServices      wbemServices      = this.scope.GetIWbemServices();
         EnumerationOptions enumerationOption = (EnumerationOptions)this.options.Clone();
         enumerationOption.ReturnImmediately = false;
         if (watcher.HaveListenersForProgress)
         {
             enumerationOption.SendStatus = true;
         }
         WmiEventSink    newSink         = watcher.GetNewSink(this.scope, enumerationOption.Context);
         SecurityHandler securityHandler = this.scope.GetSecurityHandler();
         int             num             = 0;
         try
         {
             try
             {
                 if (!(this.query.GetType() == typeof(SelectQuery)) || ((SelectQuery)this.query).Condition != null || ((SelectQuery)this.query).SelectedProperties != null || !this.options.EnumerateDeep)
                 {
                     enumerationOption.EnumerateDeep = true;
                     num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).ExecQueryAsync_(this.query.QueryLanguage, this.query.QueryString, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
                 }
                 else
                 {
                     enumerationOption.EnsureLocatable = false;
                     enumerationOption.PrototypeOnly   = false;
                     if (((SelectQuery)this.query).IsSchemaQuery)
                     {
                         num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).CreateClassEnumAsync_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
                     }
                     else
                     {
                         num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).CreateInstanceEnumAsync_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
                     }
                 }
             }
             catch (COMException cOMException1)
             {
                 COMException cOMException = cOMException1;
                 watcher.RemoveSink(newSink);
                 ManagementException.ThrowWithExtendedInfo(cOMException);
             }
         }
         finally
         {
             securityHandler.Reset();
         }
         if (((long)num & (long)-4096) != (long)-2147217408)
         {
             if (((long)num & (long)-2147483648) != (long)0)
             {
                 Marshal.ThrowExceptionForHR(num);
             }
             return;
         }
         else
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
             return;
         }
     }
     else
     {
         throw new ArgumentNullException("watcher");
     }
 }
Exemple #20
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");
			}
		}