예제 #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);
            }
        }
예제 #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");
            }
        }
예제 #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");
                }
            }
        }
        internal void RemoveSink(WmiEventSink eventSink)
        {
            try {
                lock (m_sinkCollection) {
                    m_sinkCollection.Remove(eventSink.GetHashCode());
                }

                // Release the stub as we are now disconnected
                eventSink.ReleaseStub();
            } catch {}
        }
 internal void RemoveSink(WmiEventSink eventSink)
 {
     try
     {
         lock (this.m_sinkCollection)
         {
             this.m_sinkCollection.Remove(eventSink.GetHashCode());
         }
         eventSink.ReleaseStub();
     }
     catch
     {
     }
 }
        /// <summary>
        ///    <para> Cancels all outstanding operations.</para>
        /// </summary>
        public void Cancel()
        {
            // Cancel all the sinks we have - make a copy to avoid things
            // changing under our feet
            Hashtable copiedSinkTable = new Hashtable();

            lock (m_sinkCollection)
            {
                //
                IDictionaryEnumerator sinkEnum = m_sinkCollection.GetEnumerator();

                try
                {
                    sinkEnum.Reset();

                    while (sinkEnum.MoveNext())
                    {
                        DictionaryEntry entry = (DictionaryEntry)sinkEnum.Current;
                        copiedSinkTable.Add(entry.Key, entry.Value);
                    }
                }
                catch
                {
                }
            }

            // Now step through the copy and cancel everything
            try
            {
                IDictionaryEnumerator copiedSinkEnum = copiedSinkTable.GetEnumerator();
                copiedSinkEnum.Reset();

                while (copiedSinkEnum.MoveNext())
                {
                    DictionaryEntry entry     = (DictionaryEntry)copiedSinkEnum.Current;
                    WmiEventSink    eventSink = (WmiEventSink)entry.Value;

                    try
                    {
                        eventSink.Cancel();
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }
 internal WmiEventSink GetNewSink(ManagementScope scope, object context)
 {
     try
     {
         WmiEventSink sink = WmiEventSink.GetWmiEventSink(this, context, scope, null, null);
         lock (this.m_sinkCollection)
         {
             this.m_sinkCollection.Add(sink.GetHashCode(), sink);
         }
         return(sink);
     }
     catch
     {
         return(null);
     }
 }
 internal WmiEventSink GetNewPutSink(ManagementScope scope, object context, string path, string className)
 {
     try
     {
         WmiEventSink sink = WmiEventSink.GetWmiEventSink(this, context, scope, path, className);
         lock (this.m_sinkCollection)
         {
             this.m_sinkCollection.Add(sink.GetHashCode(), sink);
         }
         return(sink);
     }
     catch
     {
         return(null);
     }
 }
        internal WmiEventSink GetNewSink(
            ManagementScope scope,
            object context)
        {
            try {
                WmiEventSink eventSink = WmiEventSink.GetWmiEventSink(this, context, scope, null, null);

                // Add it to our collection
                lock (m_sinkCollection) {
                    m_sinkCollection.Add(eventSink.GetHashCode(), eventSink);
                }

                return(eventSink);
            } catch {
                return(null);
            }
        }
        public void Cancel()
        {
            Hashtable hashtable = new Hashtable();

            lock (this.m_sinkCollection)
            {
                IDictionaryEnumerator enumerator = this.m_sinkCollection.GetEnumerator();
                try
                {
                    enumerator.Reset();
                    while (enumerator.MoveNext())
                    {
                        DictionaryEntry current = (DictionaryEntry)enumerator.Current;
                        hashtable.Add(current.Key, current.Value);
                    }
                }
                catch
                {
                }
            }
            try
            {
                IDictionaryEnumerator enumerator2 = hashtable.GetEnumerator();
                enumerator2.Reset();
                while (enumerator2.MoveNext())
                {
                    DictionaryEntry entry2 = (DictionaryEntry)enumerator2.Current;
                    WmiEventSink    sink   = (WmiEventSink)entry2.Value;
                    try
                    {
                        sink.Cancel();
                        continue;
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            catch
            {
            }
        }
        internal WmiEventSink GetNewPutSink(
            ManagementScope scope,
            object context,
            string path,
            string className)
        {
            try {
                WmiEventSink eventSink = new WmiEventSink(this, context, scope, path, className);

                // Add it to our collection
                lock (m_sinkCollection) {
                    m_sinkCollection.Add(eventSink.GetHashCode(), eventSink);
                }

                return(eventSink);
            } catch {
                return(null);
            }
        }
        internal WmiEventSink GetNewSink(ManagementScope scope, object context)
        {
            WmiEventSink wmiEventSink;

            try
            {
                WmiEventSink wmiEventSink1 = WmiEventSink.GetWmiEventSink(this, context, scope, null, null);
                lock (this.m_sinkCollection)
                {
                    this.m_sinkCollection.Add(wmiEventSink1.GetHashCode(), wmiEventSink1);
                }
                wmiEventSink = wmiEventSink1;
            }
            catch
            {
                wmiEventSink = null;
            }
            return(wmiEventSink);
        }
예제 #13
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);
                }
            }
        }
예제 #14
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 void Cancel()
        {
            Hashtable hashtables = new Hashtable();

            lock (this.m_sinkCollection)
            {
                IDictionaryEnumerator enumerator = this.m_sinkCollection.GetEnumerator();
                try
                {
                    enumerator.Reset();
                    while (enumerator.MoveNext())
                    {
                        DictionaryEntry current = (DictionaryEntry)enumerator.Current;
                        hashtables.Add(current.Key, current.Value);
                    }
                }
                catch
                {
                }
            }
            try
            {
                IDictionaryEnumerator dictionaryEnumerator = hashtables.GetEnumerator();
                dictionaryEnumerator.Reset();
                while (dictionaryEnumerator.MoveNext())
                {
                    DictionaryEntry dictionaryEntry = (DictionaryEntry)dictionaryEnumerator.Current;
                    WmiEventSink    value           = (WmiEventSink)dictionaryEntry.Value;
                    try
                    {
                        value.Cancel();
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }
예제 #16
0
 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");
     }
 }
예제 #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());
            }
        }
예제 #18
0
 private static void HackToCreateWmiEventSink()
 {
     wmiEventSinkNew = new WmiEventSink(watcherParameter, contextParameter, scopeParameter, pathParameter, classNameParameter);
 }
예제 #19
0
		internal void RemoveSink(WmiEventSink eventSink)
		{
			try
			{
				lock (this.m_sinkCollection)
				{
					this.m_sinkCollection.Remove(eventSink.GetHashCode());
				}
				eventSink.ReleaseStub();
			}
			catch
			{
			}
		}
예제 #20
0
 private static void HackToCreateWmiEventSink()
 {
     WmiEventSink.wmiEventSinkNew = new WmiEventSink(WmiEventSink.watcherParameter, WmiEventSink.contextParameter, WmiEventSink.scopeParameter, WmiEventSink.pathParameter, WmiEventSink.classNameParameter);
 }
 private static void HackToCreateWmiEventSink()
 {
     wmiEventSinkNew = new WmiEventSink(watcherParameter, contextParameter, scopeParameter, pathParameter, classNameParameter);
 }
예제 #22
0
		private static void HackToCreateWmiEventSink()
		{
			WmiEventSink.wmiEventSinkNew = new WmiEventSink(WmiEventSink.watcherParameter, WmiEventSink.contextParameter, WmiEventSink.scopeParameter, WmiEventSink.pathParameter, WmiEventSink.classNameParameter);
		}
        internal void RemoveSink (WmiEventSink eventSink)
        {
            try 
            {
                lock (m_sinkCollection) 
                {
                    m_sinkCollection.Remove (eventSink.GetHashCode ());
                }

                // Release the stub as we are now disconnected
                eventSink.ReleaseStub ();
            } 
            catch
            {
            }
        }