Export (0) Print
Expand All

WqlEventQuery Constructor (String)

Initializes a new instance of the WqlEventQuery class based on the given query string or event class name.

Namespace:  System.Management
Assembly:  System.Management (in System.Management.dll)

public WqlEventQuery(
	string queryOrEventClassName
)

Parameters

queryOrEventClassName
Type: System.String

The string representing either the entire event query or the name of the event class to query. The object will try to parse the string as a valid event query. If unsuccessful, the parser will assume that the parameter represents an event class name.

.NET Framework Security

Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

The following example initializes a WqlEventQuery by specifying a query and then initializes a WqlEventQuery by specifying an event.

using System;
using System.Management;

public class EventSample 
{
    public static void Main(string[] args) 
    {
        // Full query string specified to the constructor
        WqlEventQuery q = 
            new WqlEventQuery("SELECT * FROM Win32_ComputerShutdownEvent");

        // Only relevant event class name specified to the constructor    
        // Results in the same query as above.
        WqlEventQuery query =
            new WqlEventQuery("Win32_ComputerShutdownEvent ");

        Console.WriteLine(query.QueryString);
        return;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft