ManagementObjectSearcher.Scope 属性

定义

获取或设置要在其中查找对象的范围(该范围表示一个 WMI 命名空间)。

public:
 property System::Management::ManagementScope ^ Scope { System::Management::ManagementScope ^ get(); void set(System::Management::ManagementScope ^ value); };
public System.Management.ManagementScope Scope { get; set; }
member this.Scope : System.Management.ManagementScope with get, set
Public Property Scope As ManagementScope

属性值

范围 (命名空间) 在其中查找 WMI 对象。

示例

以下示例使用特定查询初始化 类的新实例 ManagementObjectSearcher ,然后更改该实例的范围。

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementScope ms = new ManagementScope(
            "\\\\.\\root\\cimv2");
        ms.Connect();
        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(
            "SELECT * FROM Win32_Service");
        searcher.Scope = ms;

        foreach (ManagementObject service in searcher.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 ms As ManagementScope
        ms = New ManagementScope("\\localhost\root\cimv2")
        ms.Connect()
        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher( _
            "SELECT * FROM Win32_Service")
        searcher.Scope = ms

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


    End Function 'Main
End Class

注解

更改此属性的值时, ManagementObjectSearcher 将重新绑定到新的范围。

属性值

作用域 (要在其中查找对象的命名空间) 。

.NET Framework 安全性

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

适用于