Upravit

Sdílet prostřednictvím


ManagementObjectSearcher.Scope Property

Definition

Gets or sets the scope in which to look for objects (the scope represents a WMI namespace).

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

Property Value

The scope (namespace) in which to look for the WMI objects.

Examples

The following example initializes a new instance of the ManagementObjectSearcher class with a specific query and then changes the scope of the instance.

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

Remarks

When the value of this property is changed, the ManagementObjectSearcher is re-bound to the new scope.

Property Value

The scope (namespace) in which to look for objects.

.NET Framework Security

Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

Applies to