ManagementObjectSearcher.Scope Property


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

Namespace:   System.Management
Assembly:  System.Management (in System.Management.dll)

public ManagementScope Scope { get; set; }

Property Value

Type: System.Management.ManagementScope

Returns a ManagementScope that contains the scope (namespace) in which to look for the WMI objects.

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

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

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.

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(
        ManagementObjectSearcher searcher = 
            new ManagementObjectSearcher(
            "SELECT * FROM Win32_Service");
        searcher.Scope = ms;

        foreach (ManagementObject service in searcher.Get()) 
            // show the service

.NET Framework
Available since 1.1
Return to top