Export (0) Print
Expand All

SelectQuery Constructor (String, String, String[])

Initializes a new instance of the SelectQuery class with the specified class name and condition, selecting only the specified properties.

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

public SelectQuery(
	string className,
	string condition,
	string[] selectedProperties
)

Parameters

className
Type: System.String

The name of the class from which to select.

condition
Type: System.String

The condition to be applied to instances of the selected class.

selectedProperties
Type: System.String[]

An array of property names to be returned in the query results.

.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 SelectQuery by specifying a WMI class name, condition, and array of properties.

using System;
using System.Management;

public class Sample 
{
    public static void Main(string[] args) 
    {
        String[] properties = 
            {"Name", "Handle"};

        SelectQuery s = new SelectQuery("Win32_Process",
            "Name = 'notepad.exe'", 
            properties);


        ManagementObjectSearcher searcher = 
            new ManagementObjectSearcher(
            s);

        foreach (ManagementObject o in searcher.Get()) 
        {
            // show the class
            Console.WriteLine(o.ToString());
        }
    }
}

.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