This documentation is archived and is not being maintained.

ManagementObjectSearcher Class

Retrieves a collection of management objects based on a specified query.

This class is one of the more commonly used entry points to retrieving management information. For example, it can be used to enumerate all disk drives, network adapters, processes and many more management objects on a system, or to query for all network connections that are up, services that are paused etc.

When instantiated, an instance of this class takes as input a WMI query represented in an ObjectQuery or it's derivatives, and optionally a ManagementScope representing the WMI namespace to execute the query in. It can also take additional advanced options in an EnumerationOptions object. When the Get() method on this object is invoked, the ManagementObjectSearcher executes the given query in the specified scope and returns a collection of management objects that match the query in a ManagementObjectCollection.

For a list of all members of this type, see ManagementObjectSearcher Members.


[Visual Basic]
Public Class ManagementObjectSearcher
   Inherits Component
public class ManagementObjectSearcher : Component
public __gc class ManagementObjectSearcher : public Component
public class ManagementObjectSearcher extends Component

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


using System;
using System.Management;

// This sample demonstrates perform a query using
// ManagementObjectSearcher object.
class Sample_ManagementObjectSearcher
    public static int Main(string[] args) {
        ManagementObjectSearcher searcher = new 
            ManagementObjectSearcher("select * from win32_share");
        foreach (ManagementObject share in searcher.Get()) {
            Console.WriteLine("Share = " + share["Name"]);
        return 0;
[Visual Basic] 
Imports System
Imports System.Management

' This sample demonstrates perform a query using
' ManagementObjectSearcher object.
Class Sample_ManagementObjectSearcher
    Overloads Public Shared Function Main(args() As String) As Integer
        Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_Share")
        Dim share As ManagementObject
        For Each share In searcher.Get()
            Console.WriteLine("Share = " & share("Name").ToString())
        Next share
        Return 0
    End Function
End Class

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Management

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

ManagementObjectSearcher Members | System.Management Namespace