ManagementObjectSearcher.Scope Property

Definition

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

C#
public System.Management.ManagementScope Scope { get; set; }

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.

C#
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());
        }
    }
}

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

Toode Versioonid
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)