ManagementObjectSearcher 构造函数

定义

初始化 ManagementObjectSearcher 类的新实例。

重载

ManagementObjectSearcher()

初始化 ManagementObjectSearcher 类的新实例。 设置此对象的部分属性后,可以使用此对象调用对管理信息的查询。 这是无参数构造函数。

ManagementObjectSearcher(ObjectQuery)

初始化 ManagementObjectSearcher 类的一个新实例,它用于调用有关管理信息的指定查询。

ManagementObjectSearcher(String)

初始化 ManagementObjectSearcher 类的一个新实例,它用于调用有关管理信息的指定查询。

ManagementObjectSearcher(ManagementScope, ObjectQuery)

初始化 ManagementObjectSearcher 类的一个新实例,它用于在指定范围内调用指定查询。

ManagementObjectSearcher(String, String)

初始化 ManagementObjectSearcher 类的一个新实例,它用于在指定范围内调用指定查询。

ManagementObjectSearcher(ManagementScope, ObjectQuery, EnumerationOptions)

使用指定的选项初始化 ManagementObjectSearcher 类的一个新实例,它将用于在指定范围内调用指定的查询。

ManagementObjectSearcher(String, String, EnumerationOptions)

初始化 ManagementObjectSearcher 类的一个新实例,它将用于在指定范围内使用指定选项调用指定的查询。

ManagementObjectSearcher()

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

初始化 ManagementObjectSearcher 类的新实例。 设置此对象的部分属性后,可以使用此对象调用对管理信息的查询。 这是无参数构造函数。

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

注解

.NET Framework 安全性

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

适用于

ManagementObjectSearcher(ObjectQuery)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

初始化 ManagementObjectSearcher 类的一个新实例,它用于调用有关管理信息的指定查询。

public:
 ManagementObjectSearcher(System::Management::ObjectQuery ^ query);
public ManagementObjectSearcher (System.Management.ObjectQuery query);
new System.Management.ManagementObjectSearcher : System.Management.ObjectQuery -> System.Management.ManagementObjectSearcher
Public Sub New (query As ObjectQuery)

参数

query
ObjectQuery

表示搜索器将调用的查询的 ObjectQuery

示例

以下示例使用特定查询初始化 类的新实例 ManagementObjectSearcher

using System;
using System.Management;

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

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


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

        Dim q As New _
            SelectQuery("Win32_Service", "State=""Running""")
        Dim s As New ManagementObjectSearcher(q)

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


    End Function 'Main
End Class

注解

.NET Framework 安全性

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

适用于

ManagementObjectSearcher(String)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

初始化 ManagementObjectSearcher 类的一个新实例,它用于调用有关管理信息的指定查询。

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

参数

queryString
String

对象将调用的 WMI 查询。

示例

以下示例使用特定查询初始化 类的新实例 ManagementObjectSearcher

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(
                "SELECT * FROM Win32_Service");

        foreach (ManagementObject service in s.Get())
        {
            // show the instance
            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 _
            ManagementObjectSearcher( _
            "SELECT * FROM Win32_Service")

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


    End Function 'Main
End Class

注解

.NET Framework 安全性

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

适用于

ManagementObjectSearcher(ManagementScope, ObjectQuery)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

初始化 ManagementObjectSearcher 类的一个新实例,它用于在指定范围内调用指定查询。

public:
 ManagementObjectSearcher(System::Management::ManagementScope ^ scope, System::Management::ObjectQuery ^ query);
public ManagementObjectSearcher (System.Management.ManagementScope scope, System.Management.ObjectQuery query);
new System.Management.ManagementObjectSearcher : System.Management.ManagementScope * System.Management.ObjectQuery -> System.Management.ManagementObjectSearcher
Public Sub New (scope As ManagementScope, query As ObjectQuery)

参数

scope
ManagementScope

一个 ManagementScope,表示要在其中调用查询的范围。

query
ObjectQuery

表示要调用的查询的 ObjectQuery

示例

以下示例使用特定查询和范围初始化 类的新实例 ManagementObjectSearcher

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementScope myScope =
            new ManagementScope("root\\CIMV2");
        SelectQuery q =
            new SelectQuery("Win32_LogicalDisk");
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(myScope,q);

        foreach (ManagementObject disk in s.Get())
        {
            // show the disk instance
            Console.WriteLine(disk.ToString());
        }
    }
}
Imports System.Management


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

        Dim myScope As New ManagementScope("root\CIMV2")
        Dim q As New SelectQuery("Win32_LogicalDisk")
        Dim s As New ManagementObjectSearcher(myScope, q)

        For Each disk As ManagementObject In s.Get()
            'show the disk instance
            Console.WriteLine(disk.ToString())
        Next


    End Function 'Main
End Class

注解

如果未指定作用域,则使用默认作用域 (DefaultPath) 。

.NET Framework 安全性

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

适用于

ManagementObjectSearcher(String, String)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

初始化 ManagementObjectSearcher 类的一个新实例,它用于在指定范围内调用指定查询。

public:
 ManagementObjectSearcher(System::String ^ scope, System::String ^ queryString);
public ManagementObjectSearcher (string scope, string queryString);
new System.Management.ManagementObjectSearcher : string * string -> System.Management.ManagementObjectSearcher
Public Sub New (scope As String, queryString As String)

参数

scope
String

要在其中进行查询的范围。

queryString
String

要调用的查询。

示例

以下示例使用特定查询和范围初始化 类的新实例 ManagementObjectSearcher

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(
            "root\\CIMV2",
            "SELECT * FROM Win32_Service" +
            " WHERE State='Running'");

        foreach (ManagementObject service in s.Get())
        {
            // show the instance
            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 ManagementObjectSearcher( _
            "root\CIMV2", _
        "SELECT * FROM Win32_Service WHERE State='Running'")

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


    End Function 'Main
End Class

注解

如果未指定作用域,则使用默认作用域 (DefaultPath) 。

.NET Framework 安全性

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

适用于

ManagementObjectSearcher(ManagementScope, ObjectQuery, EnumerationOptions)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

使用指定的选项初始化 ManagementObjectSearcher 类的一个新实例,它将用于在指定范围内调用指定的查询。

public:
 ManagementObjectSearcher(System::Management::ManagementScope ^ scope, System::Management::ObjectQuery ^ query, System::Management::EnumerationOptions ^ options);
public ManagementObjectSearcher (System.Management.ManagementScope scope, System.Management.ObjectQuery query, System.Management.EnumerationOptions options);
new System.Management.ManagementObjectSearcher : System.Management.ManagementScope * System.Management.ObjectQuery * System.Management.EnumerationOptions -> System.Management.ManagementObjectSearcher
Public Sub New (scope As ManagementScope, query As ObjectQuery, options As EnumerationOptions)

参数

scope
ManagementScope

ManagementScope,指定查询的范围。

query
ObjectQuery

ObjectQuery,指定将调用的查询。

options
EnumerationOptions

一个 EnumerationOptions,它指定查询将使用的附加选项。

示例

以下示例使用特定的查询、作用域和枚举选项初始化 类的新实例 ManagementObjectSearcher

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementScope scope =
            new ManagementScope("root\\CIMV2");
        SelectQuery q =
            new SelectQuery("SELECT * FROM Win32_LogicalDisk");
        EnumerationOptions o =
            new EnumerationOptions(
            null, System.TimeSpan.MaxValue,
            1, true, false, true,
            true, false, true, true);
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(scope, q, o);

        foreach (ManagementObject disk in s.Get())
        {
            // show the disk instance
            Console.WriteLine(disk.ToString());
        }
    }
}
Imports System.Management


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

        Dim scope As New ManagementScope("root\MyApp")
        Dim q As New SelectQuery("SELECT * FROM Win32_LogicalDisk")
        Dim o As New EnumerationOptions( _
            Nothing, System.TimeSpan.MaxValue, 1, _
            True, False, True, True, False, _
            True, True)
        Dim s As New ManagementObjectSearcher(scope, q, o)

        For Each disk As ManagementObject In s.Get()
            'show the disk instance
            Console.WriteLine(disk.ToString())
        Next


    End Function 'Main
End Class

注解

.NET Framework 安全性

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

适用于

ManagementObjectSearcher(String, String, EnumerationOptions)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

初始化 ManagementObjectSearcher 类的一个新实例,它将用于在指定范围内使用指定选项调用指定的查询。

public:
 ManagementObjectSearcher(System::String ^ scope, System::String ^ queryString, System::Management::EnumerationOptions ^ options);
public ManagementObjectSearcher (string scope, string queryString, System.Management.EnumerationOptions options);
new System.Management.ManagementObjectSearcher : string * string * System.Management.EnumerationOptions -> System.Management.ManagementObjectSearcher
Public Sub New (scope As String, queryString As String, options As EnumerationOptions)

参数

scope
String

将在其中调用查询的范围。

queryString
String

要调用的查询。

options
EnumerationOptions

一个 EnumerationOptions,它指定有关查询的附加选项。

示例

以下示例使用特定的查询、作用域和枚举选项初始化 类的新实例 ManagementObjectSearcher

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(
            "root\\CIMV2",
            "SELECT * FROM Win32_Service",
            new EnumerationOptions(
            null, System.TimeSpan.MaxValue,
            1, true, false, true,
            true, false, true, true));

        foreach (ManagementObject service in s.Get())
        {
            // show the service
            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 ManagementObjectSearcher( _
            "root\MyApp", _
            "SELECT * FROM Win32_Service", _
            New EnumerationOptions( _
            Nothing, System.TimeSpan.MaxValue, 1, _
            True, False, True, True, False, _
            True, True))


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


    End Function 'Main
End Class

注解

.NET Framework 安全性

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

适用于