Esempio n. 1
0
        /// <summary>
        /// Executes a query to retrieve objects.
        /// </summary>
        /// <param name="query">The query which will be executed.</param>
        /// <returns>An object collection that contains the result set of the query.</returns>
        /// <exception cref="System.ObjectDisposedException">Object already disposed.</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="query"/> is null.</exception>
        #endregion
        internal IWbemClassObjectEnumerator InternalExecuteQuery(WmiQuery query)
        {
            if (this.isDisposed)
            {
                throw new ObjectDisposedException(typeof(WmiConnection).FullName);
            }

            if (query == null)
            {
                throw new ArgumentNullException(MethodBase.GetCurrentMethod().GetParameters()[0].Name);
            }

            this.Open();

            IWbemClassObjectEnumerator enumerator;

            WbemClassObjectEnumeratorBehaviorOption behaviorOption = (WbemClassObjectEnumeratorBehaviorOption)query.EnumeratorBehaviorOption;

            if (this.IsRemote)
            {
                AuthenticationLevel authLevel = this.options.EnablePackageEncryption ? AuthenticationLevel.PacketPrivacy : AuthenticationLevel.PacketIntegrity;

                // use the native function by the extension method for a faster call
                enumerator = this.wbemServices.ExecQuery(query.ToString(), behaviorOption, this.context, authLevel, ImpersonationLevel.Impersonate, this.credential.UserName, this.credential.Password, this.Authority);
            }
            else
            {
                enumerator = this.wbemServices.ExecQuery(query.ToString(), behaviorOption, this.context);
            }

            return(enumerator);
        }
Esempio n. 2
0
        /// <summary>
        /// Executes a query to retrieve objects.
        /// </summary>
        /// <param name="query">The query which will be executed.</param>
        /// <returns>An object collection that contains the result set of the query.</returns>
        /// <exception cref="System.ObjectDisposedException">Object already disposed.</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="query"/> is null.</exception>
        #endregion
        public WmiObjectEnumerator ExecuteQuery(WmiQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(MethodBase.GetCurrentMethod().GetParameters()[0].Name);
            }

            return(new WmiObjectEnumerator(this.InternalExecuteQuery(query)));
        }