SelectQuery 构造函数

定义

初始化 SelectQuery 类的新实例。

重载

SelectQuery()

初始化 SelectQuery 类的新实例。 这是无参数构造函数。

SelectQuery(String)

为指定查询或指定类名初始化 SelectQuery 类的新实例。

SelectQuery(Boolean, String)

为架构查询初始化 SelectQuery 类的新实例(可以指定条件)。

SelectQuery(String, String)

用指定的类名和条件初始化 SelectQuery 类的新实例。

SelectQuery(String, String, String[])

在只选择指定属性的情况下,使用指定的类名和条件初始化 SelectQuery 类的新实例。

SelectQuery()

初始化 SelectQuery 类的新实例。 这是无参数构造函数。

public:
 SelectQuery();
public SelectQuery ();
Public Sub New ()

注解

.NET Framework 安全性

对直接调用方的完全信任。 此成员不能由部分信任的代码使用。 有关详细信息,请参阅 从部分受信任的代码使用库

适用于

SelectQuery(String)

为指定查询或指定类名初始化 SelectQuery 类的新实例。

public:
 SelectQuery(System::String ^ queryOrClassName);
public SelectQuery (string queryOrClassName);
new System.Management.SelectQuery : string -> System.Management.SelectQuery
Public Sub New (queryOrClassName As String)

参数

queryOrClassName
String

整个查询或要在查询中使用的类名。 此类中的分析器尝试将字符串分析为有效的 WQL SELECT 查询。 如果分析器不能成功分析,则假定该字符串为类名。

示例

以下示例通过指定查询来初始化 a SelectQuery

using System;
using System.Management;

class Sample
{
    public static void Main(string[] args)
    {
        SelectQuery sQuery =
            new SelectQuery(
            "SELECT * FROM Win32_Service WHERE State='Stopped'");

        // or

        // This is equivalent to "SELECT * FROM Win32_Service"
        SelectQuery query = new SelectQuery("Win32_Service");
    }
}
Imports System.Management


Public Class Sample
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        Dim sQuery As New SelectQuery( _
            "SELECT * FROM Win32_Service WHERE State='Stopped'")

        'or

        'This is equivalent to "SELECT * FROM Win32_Service"
        Dim query As New SelectQuery("Win32_Service")

    End Function
End Class

注解

.NET Framework 安全性

对直接调用方的完全信任。 此成员不能由部分信任的代码使用。 有关详细信息,请参阅 从部分受信任的代码使用库

适用于

SelectQuery(Boolean, String)

为架构查询初始化 SelectQuery 类的新实例(可以指定条件)。

public:
 SelectQuery(bool isSchemaQuery, System::String ^ condition);
public SelectQuery (bool isSchemaQuery, string condition);
new System.Management.SelectQuery : bool * string -> System.Management.SelectQuery
Public Sub New (isSchemaQuery As Boolean, condition As String)

参数

isSchemaQuery
Boolean

如果指示这是架构查询,则为 true;否则为 falsefalse 值在此构造函数中无效。

condition
String

形成类的结果集时要应用的条件。

示例

以下示例通过指定条件来初始化 a SelectQuery

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        SelectQuery s =
            new SelectQuery(true,
            "__CLASS = 'Win32_Service'");

        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(
            s);

        foreach (ManagementObject service in searcher.Get())
        {
            // show the class
            Console.WriteLine(service.ToString());
        }
    }
}
Imports System.Management


Public Class Sample
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        Dim s As New SelectQuery( _
            True, "__CLASS = ""Win32_Service""")

        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher(s)

        For Each service As ManagementObject In searcher.Get()
            'show the class
            Console.WriteLine(service.ToString())
        Next


    End Function 'Main
End Class

注解

.NET Framework 安全性

对直接调用方的完全信任。 此成员不能由部分信任的代码使用。 有关详细信息,请参阅 从部分受信任的代码使用库

适用于

SelectQuery(String, String)

用指定的类名和条件初始化 SelectQuery 类的新实例。

public:
 SelectQuery(System::String ^ className, System::String ^ condition);
public SelectQuery (string className, string condition);
new System.Management.SelectQuery : string * string -> System.Management.SelectQuery
Public Sub New (className As String, condition As String)

参数

className
String

要在查询中选择的类的名称。

condition
String

要在查询中应用的条件。

示例

以下示例通过指定 WMI 类名称和条件来初始化 SelectQuery a。

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        SelectQuery s =
            new SelectQuery("Win32_Service",
            "State = 'Stopped'");

        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(
            s);

        foreach (ManagementObject service in searcher.Get())
        {
            // show the class
            Console.WriteLine(service.ToString());
        }
    }
}
Imports System.Management


Public Class Sample
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        Dim s As New SelectQuery("Win32_Service", _
            "State = 'Stopped'")

        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher(s)

        For Each service As ManagementObject In searcher.Get()
            'show the class
            Console.WriteLine(service.ToString())
        Next


    End Function 'Main
End Class

注解

.NET Framework 安全性

对直接调用方的完全信任。 此成员不能由部分信任的代码使用。 有关详细信息,请参阅 从部分受信任的代码使用库

适用于

SelectQuery(String, String, String[])

在只选择指定属性的情况下,使用指定的类名和条件初始化 SelectQuery 类的新实例。

public:
 SelectQuery(System::String ^ className, System::String ^ condition, cli::array <System::String ^> ^ selectedProperties);
public SelectQuery (string className, string condition, string[] selectedProperties);
new System.Management.SelectQuery : string * string * string[] -> System.Management.SelectQuery
Public Sub New (className As String, condition As String, selectedProperties As String())

参数

className
String

将从其中进行选择的类的名称。

condition
String

要应用到选定类的实例的条件。

selectedProperties
String[]

要在查询结果中返回的属性名的数组。

示例

以下示例通过指定 WMI 类名称、条件和属性数组来初始化 a SelectQuery

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());
        }
    }
}
Imports System.Management


Public Class Sample
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        Dim properties() As String = _
            {"Name", "Handle"}

        Dim s As New SelectQuery("Win32_Process", _
            "Name = 'notepad.exe'", _
            properties)

        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher(s)

        For Each o As ManagementObject In searcher.Get()
            'show the class
            Console.WriteLine(o.ToString())
        Next


    End Function 'Main
End Class

注解

.NET Framework 安全性

对直接调用方的完全信任。 此成员不能由部分信任的代码使用。 有关详细信息,请参阅 从部分受信任的代码使用库

适用于