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"); } }
}//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()); } }
public ManagementObjectCollection Get() { this.Initialize(); IEnumWbemClassObject enumWbemClassObject = null; SecurityHandler securityHandler = this.scope.GetSecurityHandler(); EnumerationOptions enumerationOption = (EnumerationOptions)this.options.Clone(); 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(this.scope.GetIWbemServices()).ExecQuery_(this.query.QueryLanguage, this.query.QueryString, enumerationOption.Flags, enumerationOption.GetContext(), ref enumWbemClassObject); } else { enumerationOption.EnsureLocatable = false; enumerationOption.PrototypeOnly = false; if (((SelectQuery)this.query).IsSchemaQuery) { num = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).CreateClassEnum_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), ref enumWbemClassObject); } else { num = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).CreateInstanceEnum_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), ref enumWbemClassObject); } } } catch (COMException cOMException1) { COMException cOMException = cOMException1; ManagementException.ThrowWithExtendedInfo(cOMException); } } finally { securityHandler.Reset(); } if (((long)num & (long)-4096) != (long)-2147217408) { if (((long)num & (long)-2147483648) != (long)0) { Marshal.ThrowExceptionForHR(num); } } else { ManagementException.ThrowWithExtendedInfo((ManagementStatus)num); } return(new ManagementObjectCollection(this.scope, this.options, enumWbemClassObject)); }
public ManagementObjectCollection Get() { this.Initialize(); IEnumWbemClassObject ppEnum = null; SecurityHandler securityHandler = this.scope.GetSecurityHandler(); EnumerationOptions options = (EnumerationOptions)this.options.Clone(); 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(this.scope.GetIWbemServices()).CreateInstanceEnum_(((SelectQuery)this.query).ClassName, options.Flags, options.GetContext(), ref ppEnum); } else { errorCode = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).CreateClassEnum_(((SelectQuery)this.query).ClassName, options.Flags, options.GetContext(), ref ppEnum); } } else { options.EnumerateDeep = true; errorCode = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).ExecQuery_(this.query.QueryLanguage, this.query.QueryString, options.Flags, options.GetContext(), ref ppEnum); } } catch (COMException exception) { ManagementException.ThrowWithExtendedInfo(exception); } finally { securityHandler.Reset(); } if ((errorCode & 0xfffff000L) == 0x80041000L) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode); } else if ((errorCode & 0x80000000L) != 0L) { Marshal.ThrowExceptionForHR(errorCode); } return(new ManagementObjectCollection(this.scope, this.options, ppEnum)); }
//******************************************** //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 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 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 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"); } } }
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(); } }
public ManagementObjectCollection GetRelationshipClasses(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 { this.Initialize(false); IEnumWbemClassObject enumWbemClassObject = null; if (options != null) { enumerationOption = options; } else { enumerationOption = new EnumerationOptions(); } EnumerationOptions enumerationOption1 = enumerationOption; enumerationOption1.EnumerateDeep = true; RelationshipQuery relationshipQuery = new RelationshipQuery(true, this.Path.Path, relationshipClass, relationshipQualifier, thisRole); SecurityHandler securityHandler = null; int num = 0; try { securityHandler = base.Scope.GetSecurityHandler(); num = this.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQuery_(relationshipQuery.QueryLanguage, relationshipQuery.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)); } }
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 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 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 ManagementObjectCollection GetRelationshipClasses(string relationshipClass, string relationshipQualifier, 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) ? options : new EnumerationOptions(); options2.EnumerateDeep = true; RelationshipQuery query = new RelationshipQuery(true, this.Path.Path, relationshipClass, relationshipQualifier, 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)); }