コード例 #1
0
ファイル: UnixWmiNetUtils.cs プロジェクト: nickchal/pash
		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;
 }
コード例 #4
0
		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;
		}
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        //
        //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));
                }
            }
        }
コード例 #7
0
 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;
     }
 }
コード例 #8
0
 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);
     }
 }
コード例 #9
0
        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);
        }
コード例 #10
0
        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));
        }
コード例 #11
0
            /// <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);
                }
            }
コード例 #12
0
        //internal IWbemServices GetIWbemServices () {
        //  return scope.GetIWbemServices ();
        //}

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

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

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

            this.enumWbem = enumWbem;
        }
コード例 #13
0
        //********************************************
        //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;
            }
        }
コード例 #14
0
 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;
 }
コード例 #16
0
 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;
 }
コード例 #17
0
        public ManagementObjectCollection GetSubclasses(EnumerationOptions options)
        {
            if (this.Path == null)
            {
                throw new InvalidOperationException();
            }
            this.Initialize(false);
            IEnumWbemClassObject ppEnum   = null;
            EnumerationOptions   options2 = (options == null) ? new EnumerationOptions() : ((EnumerationOptions)options.Clone());

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

            try
            {
                securityHandler = base.Scope.GetSecurityHandler();
                errorCode       = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnum_(base.ClassName, options2.Flags, options2.GetContext(), ref ppEnum);
            }
            finally
            {
                if (securityHandler != null)
                {
                    securityHandler.Reset();
                }
            }
            if (errorCode < 0)
            {
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                }
                else
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
            }
            return(new ManagementObjectCollection(base.Scope, options2, ppEnum));
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        /// <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);
        }
コード例 #20
0
        /// <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);
        }
コード例 #21
0
        //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);
                }
            }
コード例 #23
0
ファイル: UnixWmiNetUtils.cs プロジェクト: nickchal/pash
		internal static int CloneEnumWbemClassObject(out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IEnumWbemClassObject pCurrentEnumWbemClassObject, string strUser, IntPtr strPassword, string strAuthority)
		{
			ppEnum = pCurrentEnumWbemClassObject;
			return 0;
		}
コード例 #24
0
ファイル: UnixWmiNetUtils.cs プロジェクト: nickchal/pash
		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;
		}
コード例 #25
0
ファイル: ManagementScope.cs プロジェクト: JianwenSun/cc
 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;
 }
コード例 #26
0
ファイル: EventSource.cs プロジェクト: modulexcite/pash-1
 int System.Management.IWbemServices_Old.ExecQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum)
 {
     ppEnum = null;
     return(-2147217396);
 }
コード例 #27
0
        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);
        }
コード例 #28
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);
        }
コード例 #29
0
		internal SecuredIEnumWbemClassObjectHandler(ManagementScope theScope, IEnumWbemClassObject pEnumWbemClassObject)
		{
			this.scope = theScope;
			this.pEnumWbemClassObjectsecurityHelper = pEnumWbemClassObject;
		}
コード例 #30
0
		public int Clone_ (out IEnumWbemClassObject ppEnum)
		{
			ppEnum = this;
			return 0;
		}
コード例 #31
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);
 }
コード例 #32
0
 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);
 }
コード例 #33
0
ファイル: UnixWbemServices.cs プロジェクト: nickchal/pash
		public int ExecNotificationQuery_ (string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum)
		{
			ppEnum = new UnixEnumWbemClassObject(WMIDatabaseFactory.Get (_currentNamespace, strQuery));
			return 0;
		}
コード例 #34
0
ファイル: UnixWbemServices.cs プロジェクト: nickchal/pash
		public int CreateInstanceEnum_ (string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum)
		{
			var items = WMIDatabaseFactory.Get (_currentNamespace, strFilter);
			ppEnum = new UnixEnumWbemClassObject(items);
			return 0;
		}
コード例 #35
0
ファイル: UnixWbemServices.cs プロジェクト: nickchal/pash
		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));
            }
        }
 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);
     }
 }
コード例 #38
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);
 }
コード例 #39
0
 internal SecuredIEnumWbemClassObjectHandler GetSecuredIEnumWbemClassObjectHandler(IEnumWbemClassObject pEnumWbemClassObject)
 {
     return(new SecuredIEnumWbemClassObjectHandler(this, pEnumWbemClassObject));
 }
コード例 #40
0
 internal static int CloneEnumWbemClassObject(out IEnumWbemClassObject ppEnum, int impLevel, int authnLevel, IEnumWbemClassObject pCurrentEnumWbemClassObject, string strUser, IntPtr strPassword, string strAuthority)
 {
     ppEnum = pCurrentEnumWbemClassObject;
     return(0);
 }
コード例 #41
0
ファイル: ManagementScope.cs プロジェクト: JianwenSun/cc
  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;
 }
コード例 #42
0
ファイル: EventSource.cs プロジェクト: modulexcite/pash-1
 int System.Management.IWbemServices_Old.CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum)
 {
     ppEnum = null;
     return(-2147217396);
 }
コード例 #43
0
 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;
 }
コード例 #44
0
        //********************************************
        //Get()
        //********************************************
        /// <overload>
        ///    Invokes the specified WMI query and returns the resulting collection.
        /// </overload>
        /// <summary>
        ///    <para>Invokes the specified WMI query and returns the
        ///       resulting collection.</para>
        /// </summary>
        /// <returns>
        /// <para>A <see cref='System.Management.ManagementObjectCollection'/> containing the objects that match the
        ///    specified query.</para>
        /// </returns>
        public ManagementObjectCollection Get()
        {
            Initialize();
            IEnumWbemClassObject ew = null;
            SecurityHandler      securityHandler = scope.GetSecurityHandler();
            EnumerationOptions   enumOptions     = (EnumerationOptions)options.Clone();

            int status = (int)ManagementStatus.NoError;

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

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

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

            //Create a new collection object for the results

            return(new ManagementObjectCollection(scope, options, ew));
        }//Get()
コード例 #45
0
        /// <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;
 }
コード例 #47
0
ファイル: EventSource.cs プロジェクト: nickchal/pash
		int System.Management.IWbemServices_Old.CreateInstanceEnum_(string strFilter, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum)
		{
			ppEnum = null;
			return -2147217396;
		}
コード例 #48
0
ファイル: UnixWmiNetUtils.cs プロジェクト: nickchal/pash
		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;
		}
コード例 #49
0
ファイル: ManagementScope.cs プロジェクト: nickchal/pash
		internal SecuredIEnumWbemClassObjectHandler GetSecuredIEnumWbemClassObjectHandler(IEnumWbemClassObject pEnumWbemClassObject)
		{
			return new SecuredIEnumWbemClassObjectHandler(this, pEnumWbemClassObject);
		}
コード例 #50
0
            /// <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);
                }
            }
コード例 #51
0
ファイル: UnixWbemServices.cs プロジェクト: nickchal/pash
		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;
		}
コード例 #52
0
 public int Clone_(out IEnumWbemClassObject ppEnum)
 {
     ppEnum = this;
     return(0);
 }
 internal SecuredIEnumWbemClassObjectHandler(ManagementScope theScope, IEnumWbemClassObject pEnumWbemClassObject)
 {
     this.scope = theScope;
     this.pEnumWbemClassObjectsecurityHelper = pEnumWbemClassObject;
 }
コード例 #54
0
ファイル: EventSource.cs プロジェクト: nickchal/pash
		int System.Management.IWbemServices_Old.ExecQuery_(string strQueryLanguage, string strQuery, int lFlags, IWbemContext pCtx, out IEnumWbemClassObject ppEnum)
		{
			ppEnum = null;
			return -2147217396;
		}
コード例 #55
0
        //********************************************
        //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;
            }
        }
 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;
 }
 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;
     }
 }