ManagementObjectSearcher.Scope Właściwość

Definicja

Pobiera lub ustawia zakres, w którym mają być szukane obiekty (zakres reprezentuje przestrzeń nazw 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

Wartość właściwości

Zakres (przestrzeń nazw), w którym należy wyszukać obiekty WMI.

Przykłady

Poniższy przykład inicjuje nowe wystąpienie ManagementObjectSearcher klasy z określonym zapytaniem, a następnie zmienia zakres wystąpienia.

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

Uwagi

Po zmianie ManagementObjectSearcher wartości tej właściwości element jest ponownie powiązany z nowym zakresem.

Wartość właściwości

Zakres (przestrzeń nazw), w którym należy szukać obiektów.

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy