Export (0) Print
Expand All

ObjectQuery Class

Represents a management query that returns instances or classes.

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

System.Object
   System.Management.ManagementQuery
      System.Management.ObjectQuery
         System.Management.WqlObjectQuery

[Visual Basic]
Public Class ObjectQuery
   Inherits ManagementQuery
[C#]
public class ObjectQuery : ManagementQuery
[C++]
public __gc class ObjectQuery : public ManagementQuery
[JScript]
public class ObjectQuery extends ManagementQuery

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.

Remarks

This class or its derivatives are used to specify a query in the ManagementObjectSearcher. Use a more specific query class whenever possible.

Example

[C#] 
using System;
using System.Management;

// This sample demonstrates creating a query.

class Sample_ObjectQuery
{
    public static int Main(string[] args)
    {
        ObjectQuery objectQuery = new ObjectQuery("select * from Win32_Share");
        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(objectQuery);
        foreach (ManagementObject share in searcher.Get())
        {
            Console.WriteLine("Share = " + share["Name"]);
        }
        return 0;
    }
}
   
[Visual Basic] 
Imports System
Imports System.Management

' This sample demonstrates creating a query.

Class Sample_ObjectQuery
    Overloads Public Shared Function Main(args() As String) As Integer
        Dim objectQuery As New ObjectQuery("select * from Win32_Share")
        Dim searcher As New ManagementObjectSearcher(objectQuery)
        Dim share As ManagementObject
        For Each share In searcher.Get()
            Console.WriteLine("Share = " & share("Name"))
        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.

Requirements

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

ObjectQuery Members | System.Management Namespace

Show:
© 2014 Microsoft