internal static int CreateClassEnumWmi(string strSuperclass, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { var svc = pCurrentNamespace as UnixWbemServices; var items = WMIDatabaseFactory.Get (svc.CurrentNamespace, "SELECT * FROM " + strSuperclass); ppEnum = new UnixEnumWbemClassObject(items); return 0; }
public ManagementEventWatcher(ManagementScope scope, EventQuery query, EventWatcherOptions options) { if (scope != null) { this.scope = ManagementScope._Clone(scope, new IdentifierChangedEventHandler(this.HandleIdentifierChange)); } else { this.scope = ManagementScope._Clone(null, new IdentifierChangedEventHandler(this.HandleIdentifierChange)); } if (query != null) { this.query = (EventQuery) query.Clone(); } else { this.query = new EventQuery(); } this.query.IdentifierChanged += new IdentifierChangedEventHandler(this.HandleIdentifierChange); if (options != null) { this.options = (EventWatcherOptions) options.Clone(); } else { this.options = new EventWatcherOptions(); } this.options.IdentifierChanged += new IdentifierChangedEventHandler(this.HandleIdentifierChange); this.enumWbem = null; this.cachedCount = 0; this.cacheIndex = 0; this.sink = null; this.delegateInvoker = new WmiDelegateInvoker(this); }
internal int CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, ref IEnumWbemClassObject ppEnum) { int num = -2147217407; if (this.scope != null) { num = WmiNetUtilsHelper.CreateInstanceEnumWmi_f(strFilter, lFlags, pCtx, out ppEnum, (int) this.scope.Options.Authentication, (int) this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority); } return num; }
internal int Clone_(ref IEnumWbemClassObject ppEnum) { int num = -2147217407; if (this.scope != null) { num = WmiNetUtilsHelper.CloneEnumWbemClassObject_f(out ppEnum, (int)this.scope.Options.Authentication, (int)this.scope.Options.Impersonation, this.pEnumWbemClassObjectsecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority); } return num; }
public ManagementObjectCollection GetInstances(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 = 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()).CreateInstanceEnum_(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)); } }
// //IEnumerable methods // //**************************************** //GetEnumerator //**************************************** /// <summary> /// <para>Returns the enumerator for the collection.</para> /// </summary> /// <returns> /// An <see cref='System.Collections.IEnumerator'/>that can be used to iterate through the /// collection. /// </returns> public ManagementObjectEnumerator GetEnumerator() { if (isDisposed) { throw new ObjectDisposedException(name); } // Unless this is the first enumerator, we have // to clone. This may throw if we are non-rewindable. lock (firstEnum) { if (firstEnum.firstEnum) { firstEnum.firstEnum = false; return(new ManagementObjectEnumerator(this, enumWbem)); } else { IEnumWbemClassObject enumWbemClone = null; int status = (int)ManagementStatus.NoError; try { status = enumWbem.Clone_(out enumWbemClone); scope.GetSecurityHandler().Secure(enumWbemClone); if ((status & 0x80000000) == 0) { //since the original enumerator might not be reset, we need //to reset the new one. status = enumWbemClone.Reset_(); } } catch (Exception e) { ManagementException.ThrowWithExtendedInfo(e); } if ((status & 0xfffff000) == 0x80041000) { // BUGBUG : release callResult. ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) { // BUGBUG : release callResult. Marshal.ThrowExceptionForHR(status); } return(new ManagementObjectEnumerator(this, enumWbemClone)); } } }
public void Stop() { if (this.enumWbem != null) { Marshal.ReleaseComObject(this.enumWbem); this.enumWbem = null; this.FireStopped(new StoppedEventArgs(this.options.Context, 0x40006)); } if (this.sink != null) { this.sink.Cancel(); this.sink = null; } }
public void Dispose() { if (!this.isDisposed) { if (this.enumWbem != null) { Marshal.ReleaseComObject(this.enumWbem); this.enumWbem = null; } this.cachedObjects = null; this.collectionObject = null; this.isDisposed = true; GC.SuppressFinalize(this); } }
internal void Secure(IEnumWbemClassObject wbemEnum) { if (null == securityHelper) { securityHelper = (IWmiSec) new WmiSec(); } securityHelper.BlessIEnumWbemClassObject( ref wbemEnum, options.Username, options.GetPassword(), options.Authority, (int)options.Impersonation, (int)options.Authentication); }
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)); }
/// <summary> /// Release resources associated with this object. After this /// method has been called any attempt to use this object will /// result in an ObjectDisposedException being thrown. /// </summary> public void Dispose() { if (!isDisposed) { if (null != enumWbem) { Marshal.ReleaseComObject(enumWbem); enumWbem = null; } isDisposed = true; // Here one would call base.Dispose() if this class had a superclass GC.SuppressFinalize(this); } }
//internal IWbemServices GetIWbemServices () { // return scope.GetIWbemServices (); //} //internal ConnectionOptions Connection { // get { return scope.Connection; } //} //Constructor internal ManagementObjectCollection( ManagementScope scope, EnumerationOptions options, IEnumWbemClassObject enumWbem) { if (null != options) this.options = (EnumerationOptions) options.Clone(); else this.options = new EnumerationOptions (); if (null != scope) this.scope = (ManagementScope)scope.Clone (); else this.scope = ManagementScope._Clone(null); this.enumWbem = enumWbem; }
//******************************************** //Stop //******************************************** /// <summary> /// <para>Cancels the subscription whether it is synchronous or asynchronous.</para> /// </summary> public void Stop() { //For semi-synchronous, release the WMI enumerator to cancel the subscription if (null != enumWbem) { Marshal.ReleaseComObject(enumWbem); enumWbem = null; FireStopped(new StoppedEventArgs(options.Context, (int)ManagementStatus.OperationCanceled)); } // In async mode cancel the call to the sink - this will // unwind the operation and cause a Stopped message if (null != sink) { sink.Cancel(); sink = null; } }
public ManagementObjectCollection.ManagementObjectEnumerator GetEnumerator() { if (!this.isDisposed) { if (!this.options.Rewindable) { return(new ManagementObjectCollection.ManagementObjectEnumerator(this, this.enumWbem)); } else { IEnumWbemClassObject enumWbemClassObject = null; int num = 0; try { num = this.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Clone_(ref enumWbemClassObject); if (((long)num & (long)-2147483648) == (long)0) { num = this.scope.GetSecuredIEnumWbemClassObjectHandler(enumWbemClassObject).Reset_(); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; ManagementException.ThrowWithExtendedInfo(cOMException); } 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.ManagementObjectEnumerator(this, enumWbemClassObject)); } } else { throw new ObjectDisposedException(ManagementObjectCollection.name); } }
internal ManagementObjectCollection(ManagementScope scope, EnumerationOptions options, IEnumWbemClassObject enumWbem) { if (options != null) { this.options = (EnumerationOptions) options.Clone(); } else { this.options = new EnumerationOptions(); } if (scope != null) { this.scope = scope.Clone(); } else { this.scope = ManagementScope._Clone(null); } this.enumWbem = enumWbem; }
internal ManagementObjectCollection(ManagementScope scope, EnumerationOptions options, IEnumWbemClassObject enumWbem) { if (options == null) { this.options = new EnumerationOptions(); } else { this.options = (EnumerationOptions)options.Clone(); } if (scope == null) { this.scope = ManagementScope._Clone(null); } else { this.scope = scope.Clone(); } this.enumWbem = enumWbem; }
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 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)); }
/// <summary> /// <para> Initializes a new instance of the <see cref='System.Management.ManagementEventWatcher'/> class /// that listens for events conforming to the given WMI event query, according to the specified /// options. For this variant, the query and the scope are specified objects. The /// options object can specify options such as timeout and context information.</para> /// </summary> /// <param name='scope'>A <see cref='System.Management.ManagementScope'/> object representing the scope (namespace) in which the watcher will listen for events.</param> /// <param name=' query'>An <see cref='System.Management.EventQuery'/> object representing a WMI event query, which determines the events for which the watcher will listen.</param> /// <param name='options'>An <see cref='System.Management.EventWatcherOptions'/> object representing additional options used to watch for events. </param> public ManagementEventWatcher( ManagementScope scope, EventQuery query, EventWatcherOptions options) { if (null != scope) { this.scope = ManagementScope._Clone(scope, new IdentifierChangedEventHandler(HandleIdentifierChange)); } else { this.scope = ManagementScope._Clone(null, new IdentifierChangedEventHandler(HandleIdentifierChange)); } if (null != query) { this.query = (EventQuery)query.Clone(); } else { this.query = new EventQuery(); } this.query.IdentifierChanged += new IdentifierChangedEventHandler(HandleIdentifierChange); if (null != options) { this.options = (EventWatcherOptions)options.Clone(); } else { this.options = new EventWatcherOptions(); } this.options.IdentifierChanged += new IdentifierChangedEventHandler(HandleIdentifierChange); enumWbem = null; cachedCount = 0; cacheIndex = 0; sink = null; delegateInvoker = new WmiDelegateInvoker(this); }
/// <summary> /// <para>Creates a new watcher that will listen for events conforming to the given WMI /// event query, in the given WMI scope, and according to the specified options. For /// this variant the query and the scope are specified objects. The options object /// specifies options such as a timeout and possibly context information.</para> /// </summary> public ManagementEventWatcher( ManagementScope scope, EventQuery query, EventWatcherOptions options) { if (null != scope) { Scope = scope; } else { Scope = new ManagementScope(); } if (null != query) { Query = query; } else { Query = new EventQuery(); } if (null != options) { Options = options; } else { Options = new EventWatcherOptions(); } enumWbem = null; cachedCount = 0; cacheIndex = 0; sink = null; delegateInvoker = new WmiDelegateInvoker(this); }
//internal ConnectionOptions Connection { // get { return scope.Connection; } //} //Constructor internal ManagementObjectCollection( ManagementScope scope, EnumerationOptions options, IEnumWbemClassObject enumWbem) { if (null != options) { this.options = (EnumerationOptions)options.Clone(); } else { this.options = new EnumerationOptions(); } if (null != scope) { this.scope = (ManagementScope)scope.Clone(); } this.enumWbem = enumWbem; current = null; firstEnum = new FirstEnum(); }
/// <summary> /// Releases resources associated with this object. After this /// method has been called, an attempt to use this object will /// result in an ObjectDisposedException being thrown. /// </summary> public void Dispose() { if (!isDisposed) { if (null != enumWbem) { Marshal.ReleaseComObject(enumWbem); enumWbem = null; } cachedObjects = null; // DO NOT dispose of collectionObject. It is merely a reference - its lifetime // exceeds that of this object. If collectionObject.Dispose was to be done here, // a reference count would be needed. // collectionObject = null; isDisposed = true; GC.SuppressFinalize(this); } }
internal static int CloneEnumWbemClassObject(out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IEnumWbemClassObject pCurrentEnumWbemClassObject, string strUser, IntPtr strPassword, string strAuthority) { ppEnum = pCurrentEnumWbemClassObject; return 0; }
internal static int ExecNotificationQueryWmi(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { ppEnum = null; return 0; }
internal int Clone_(ref IEnumWbemClassObject ppEnum) { int status = (int)tag_WBEMSTATUS.WBEM_E_FAILED; if( null != scope) { IntPtr password = scope.Options.GetPassword(); status = WmiNetUtilsHelper.CloneEnumWbemClassObject_f( out ppEnum, (int)scope.Options.Authentication, (int)scope.Options.Impersonation, pEnumWbemClassObjectsecurityHelper, scope.Options.Username, password, scope.Options.Authority); System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(password); } return status; }
int System.Management.IWbemServices_Old.ExecQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = null; return(-2147217396); }
internal static int CreateInstanceEnumWmi(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { var svc = pCurrentNamespace as UnixWbemServices; var items = WMIDatabaseFactory.Get(svc.CurrentNamespace, "SELECT * FROM " + strFilter); ppEnum = new UnixEnumWbemClassObject(items); return(0); }
internal static int ExecQueryWmi(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { var svc = pCurrentNamespace as UnixWbemServices; IEnumerable <IWbemClassObject_DoNotMarshal> list = WMIDatabaseFactory.Get(svc.CurrentNamespace, strQuery); ppEnum = new UnixEnumWbemClassObject(list); return(0); }
internal SecuredIEnumWbemClassObjectHandler(ManagementScope theScope, IEnumWbemClassObject pEnumWbemClassObject) { this.scope = theScope; this.pEnumWbemClassObjectsecurityHelper = pEnumWbemClassObject; }
public int Clone_ (out IEnumWbemClassObject ppEnum) { ppEnum = this; return 0; }
int IWbemServices_Old.ExecQuery_([In, MarshalAs(UnmanagedType.BStr)] string strQueryLanguage, [In, MarshalAs(UnmanagedType.BStr)] string strQuery, [In] int lFlags, [In, MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [MarshalAs(UnmanagedType.Interface)] out IEnumWbemClassObject ppEnum) { ppEnum = null; return(-2147217396); }
int IWbemServices_Old.CreateInstanceEnum_([In, MarshalAs(UnmanagedType.BStr)] string strFilter, [In] int lFlags, [In, MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [MarshalAs(UnmanagedType.Interface)] out IEnumWbemClassObject ppEnum) { ppEnum = null; return(-2147217396); }
public int ExecNotificationQuery_ (string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = new UnixEnumWbemClassObject(WMIDatabaseFactory.Get (_currentNamespace, strQuery)); return 0; }
public int CreateInstanceEnum_ (string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { var items = WMIDatabaseFactory.Get (_currentNamespace, strFilter); ppEnum = new UnixEnumWbemClassObject(items); return 0; }
public int CreateClassEnum_ (string strSuperclass, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = null; return 0; }
// //IEnumerable methods // //**************************************** //GetEnumerator //**************************************** /// <summary> /// <para>Returns the enumerator for the collection. If the collection was retrieved from an operation that /// specified the EnumerationOptions.Rewindable = false only one iteration through this enumerator is allowed. /// Note that this applies to using the Count property of the collection as well since an iteration over the collection /// is required. Due to this, code using the Count property should never specify EnumerationOptions.Rewindable = false. /// </para> /// </summary> /// <returns> /// An <see cref='System.Collections.IEnumerator'/>that can be used to iterate through the /// collection. /// </returns> public ManagementObjectEnumerator GetEnumerator() { if (isDisposed) { throw new ObjectDisposedException(name); } // // We do not clone the enumerator if its the first enumerator. // If it is the first enumerator we pass the reference // to the enumerator implementation rather than a clone. If the enumerator is used // from within a foreach statement in the client code, the foreach statement will // dec the ref count on the reference which also happens to be the reference to the // original enumerator causing subsequent uses of the collection to fail. // To prevent this we always clone the enumerator (assuming its a rewindable enumerator) // to avoid invalidating the collection. // // If its a forward only enumerator we simply pass back the original enumerator (i.e. // not cloned) and if it gets disposed we end up throwing the next time its used. Essentially, // the enumerator becomes the collection. // // Unless this is the first enumerator, we have // to clone. This may throw if we are non-rewindable. if (this.options.Rewindable == true) { IEnumWbemClassObject enumWbemClone = null; int status = (int)ManagementStatus.NoError; try { status = scope.GetSecuredIEnumWbemClassObjectHandler(enumWbem).Clone_(ref enumWbemClone); if ((status & 0x80000000) == 0) { //since the original enumerator might not be reset, we need //to reset the new one. status = scope.GetSecuredIEnumWbemClassObjectHandler(enumWbemClone).Reset_(); } } catch (COMException e) { ManagementException.ThrowWithExtendedInfo(e); } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } return(new ManagementObjectEnumerator(this, enumWbemClone)); } else { // // Notice that we use the original enumerator and hence enum position is retained. // For example, if the client code manually walked half the collection and then // used a foreach statement, the foreach statement would continue from where the // manual walk ended. // return(new ManagementObjectEnumerator(this, enumWbem)); } }
internal static int ExecNotificationQueryWmi(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { ppEnum = null; return(0); }
internal SecuredIEnumWbemClassObjectHandler GetSecuredIEnumWbemClassObjectHandler(IEnumWbemClassObject pEnumWbemClassObject) { return(new SecuredIEnumWbemClassObjectHandler(this, pEnumWbemClassObject)); }
internal static int CloneEnumWbemClassObject(out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IEnumWbemClassObject pCurrentEnumWbemClassObject, string strUser, IntPtr strPassword, string strAuthority) { ppEnum = pCurrentEnumWbemClassObject; return(0); }
internal int ExecNotificationQuery_(string strQueryLanguage, string strQuery, Int32 lFlags, IWbemContext pCtx, ref IEnumWbemClassObject ppEnum) { int status = (int)tag_WBEMSTATUS.WBEM_E_FAILED; if( null != scope) { IntPtr password = scope.Options.GetPassword(); status = WmiNetUtilsHelper.ExecNotificationQueryWmi_f(strQueryLanguage, strQuery, lFlags, pCtx, out ppEnum, (int)scope.Options.Authentication, (int)scope.Options.Impersonation, pWbemServiecsSecurityHelper, scope.Options.Username, password, scope.Options.Authority); System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(password); } return status; }
int System.Management.IWbemServices_Old.CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = null; return(-2147217396); }
internal ManagementObjectEnumerator(ManagementObjectCollection collectionObject, IEnumWbemClassObject enumWbem) { this.enumWbem = enumWbem; this.collectionObject = collectionObject; this.cachedObjects = new IWbemClassObjectFreeThreaded[collectionObject.options.BlockSize]; this.cachedCount = 0; this.cacheIndex = -1; this.atEndOfCollection = false; }
//******************************************** //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()
/// <summary> /// <para> Initializes a new instance of the <see cref='System.Management.ManagementEventWatcher'/> class /// that listens for events conforming to the given WMI event query, according to the specified /// options. For this variant, the query and the scope are specified objects. The /// options object can specify options such as timeout and context information.</para> /// </summary> /// <param name='scope'>A <see cref='System.Management.ManagementScope'/> object representing the scope (namespace) in which the watcher will listen for events.</param> /// <param name=' query'>An <see cref='System.Management.EventQuery'/> object representing a WMI event query, which determines the events for which the watcher will listen.</param> /// <param name='options'>An <see cref='System.Management.EventWatcherOptions'/> object representing additional options used to watch for events. </param> public ManagementEventWatcher( ManagementScope scope, EventQuery query, EventWatcherOptions options) { if (null != scope) this.scope = ManagementScope._Clone(scope, new IdentifierChangedEventHandler(HandleIdentifierChange)); else this.scope = ManagementScope._Clone(null, new IdentifierChangedEventHandler(HandleIdentifierChange)); if (null != query) this.query = (EventQuery)query.Clone(); else this.query = new EventQuery(); this.query.IdentifierChanged += new IdentifierChangedEventHandler(HandleIdentifierChange); if (null != options) this.options = (EventWatcherOptions)options.Clone(); else this.options = new EventWatcherOptions(); this.options.IdentifierChanged += new IdentifierChangedEventHandler(HandleIdentifierChange); enumWbem = null; cachedCount = 0; cacheIndex = 0; sink = null; delegateInvoker = new WmiDelegateInvoker (this); }
internal int ExecNotificationQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, ref IEnumWbemClassObject ppEnum) { int num = -2147217407; if (this.scope != null) { num = WmiNetUtilsHelper.ExecNotificationQueryWmi_f(strQueryLanguage, strQuery, lFlags, pCtx, out ppEnum, (int) this.scope.Options.Authentication, (int) this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority); } return num; }
int System.Management.IWbemServices_Old.CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = null; return -2147217396; }
internal static int ExecQueryWmi(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IWbemServices pCurrentNamespace, string strUser, IntPtr strPassword, string strAuthority) { var svc = pCurrentNamespace as UnixWbemServices; IEnumerable<IWbemClassObject_DoNotMarshal> list = WMIDatabaseFactory.Get(svc.CurrentNamespace, strQuery); ppEnum = new UnixEnumWbemClassObject(list); return 0; }
internal SecuredIEnumWbemClassObjectHandler GetSecuredIEnumWbemClassObjectHandler(IEnumWbemClassObject pEnumWbemClassObject) { return new SecuredIEnumWbemClassObjectHandler(this, pEnumWbemClassObject); }
/// <summary> /// Releases resources associated with this object. After this /// method has been called, an attempt to use this object will /// result in an ObjectDisposedException being thrown. /// </summary> public void Dispose () { if (!isDisposed) { if (null != enumWbem) { Marshal.ReleaseComObject (enumWbem); enumWbem = null; } cachedObjects = null; // DO NOT dispose of collectionObject. It is merely a reference - its lifetime // exceeds that of this object. If collectionObject.Dispose was to be done here, // a reference count would be needed. // collectionObject = null; isDisposed = true; GC.SuppressFinalize (this); } }
public int ExecQuery_ (string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { IEnumerable<IWbemClassObject_DoNotMarshal> list = WMIDatabaseFactory.Get(_currentNamespace, strQuery); ppEnum = new UnixEnumWbemClassObject(list); return 0; }
public int Clone_(out IEnumWbemClassObject ppEnum) { ppEnum = this; return(0); }
int System.Management.IWbemServices_Old.ExecQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum) { ppEnum = null; return -2147217396; }
//******************************************** //Stop //******************************************** /// <summary> /// <para>Cancels the subscription whether it is synchronous or asynchronous.</para> /// </summary> public void Stop() { //For semi-synchronous, release the WMI enumerator to cancel the subscription if (null != enumWbem) { Marshal.ReleaseComObject(enumWbem); enumWbem = null; FireStopped (new StoppedEventArgs (options.Context, (int)ManagementStatus.OperationCanceled)); } // In async mode cancel the call to the sink - this will // unwind the operation and cause a Stopped message if (null != sink) { sink.Cancel (); sink = null; } }