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.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft