ManagementObjectSearcher Constructor (ManagementScope, ObjectQuery)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query in the specified scope.

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

public ManagementObjectSearcher(
	ManagementScope scope,
	ObjectQuery query


Type: System.Management.ManagementScope

A ManagementScope representing the scope in which to invoke the query.

Type: System.Management.ObjectQuery

An ObjectQuery representing the query to be invoked.

If no scope is specified, the default scope (DefaultPath) is used.

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 scope.

using System;
using System.Management;

public class Sample 
    public static void Main(string[] args) 
        ManagementScope myScope = 
            new ManagementScope("root\\CIMV2");
        SelectQuery q = 
            new SelectQuery("Win32_LogicalDisk");
        ManagementObjectSearcher s = 
            new ManagementObjectSearcher(myScope,q);

        foreach (ManagementObject disk in s.Get()) 
            // show the disk instance

.NET Framework
Available since 1.1
Return to top