/// <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); }
/// <summary> /// Executes a query to retrieve objects. /// </summary> /// <param name="this">The <see cref="IWbemServices"/> object which will be used.</param> /// <param name="query">The query which will be executed.</param> /// <param name="enumeratorBehaviorOption">Flag for the behavior of the created enumerator.</param> /// <param name="ctx"> /// Typically, this is NULL. /// Otherwise, this is an <see cref="WmiLight.Wbem.IWbemContext"/> object required by one or more dynamic class providers. /// </param> /// <returns>The enumerator for the results of the query.</returns> #endregion internal static IWbemClassObjectEnumerator ExecQuery(this IWbemServices @this, string query, WbemClassObjectEnumeratorBehaviorOption enumeratorBehaviorOption, IWbemContext ctx) { IWbemClassObjectEnumerator enumerator; HResult hr = @this.ExecQuery("WQL", query, enumeratorBehaviorOption, ctx, out enumerator); if (hr.Failed) { throw (Exception)hr; } return(enumerator); }
/// <summary> /// Sets the authentication information and executes a query to retrieve objects. /// </summary> /// <param name="this">The <see cref="WmiLight.Wbem.IWbemServices"/> object which will by wrapped with a proxy.</param> /// <param name="query">The query which will be executed.</param> /// <param name="enumeratorBehaviorOption">Flag for the behavior of the created enumerator.</param> /// <param name="ctx"> /// Typically, this is NULL. /// Otherwise, this is an <see cref="WmiLight.Wbem.IWbemContext"/> object required by one or more dynamic class providers. /// </param> /// <param name="impersonationLevel">The impersonation level which will be used.</param> /// <param name="authenticationLevel">The authentication level which will be used.</param> /// <param name="userName">The name of the user.</param> /// <param name="password">The password of the user.</param> /// <param name="authority"> /// The authority to be used to authenticate the specified user. /// <para /> /// Example: "ntlmdomain:MYDOMAIN" /// </param> /// <returns>The enumerator for the results of the query.</returns> #endregion internal static IWbemClassObjectEnumerator ExecQuery(this IWbemServices @this, string query, WbemClassObjectEnumeratorBehaviorOption enumeratorBehaviorOption, IWbemContext ctx, AuthenticationLevel impersonationLevel, ImpersonationLevel authenticationLevel, string userName, string password, string authority) { IWbemClassObjectEnumerator enumerator; HResult hr = NativeMethods.ExecQueryWmi("WQL", query, enumeratorBehaviorOption, ctx, out enumerator, impersonationLevel, authenticationLevel, @this, userName, password, authority); if (hr.Failed) { throw (Exception)hr; } return(enumerator); }