共用方式為


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 安全性

完全信任立即呼叫者。 這個成員無法供部分信任的程式碼使用。 如需詳細資訊,請參閱 使用部分信任程式代碼的連結庫

適用於