Export (0) Print
Expand All

ManagementObjectCollection Class

Represents different collections of management objects retrieved through WMI. The objects in this collection are of ManagementBaseObject-derived types, including ManagementObject and ManagementClass.

The collection can be the result of a WMI query executed through a ManagementObjectSearcher object, or an enumeration of management objects of a specified type retrieved through a ManagementClass representing that type. In addition, this can be a collection of management objects related in a specified way to a specific management object - in this case the collection would be retrieved through a method such as GetRelated.

The collection can be walked using the ManagementObjectCollection.ManagementObjectEnumerator and objects in it can be inspected or manipulated for various management tasks.

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

System.Object
   System.Management.ManagementObjectCollection

[Visual Basic]
Public Class ManagementObjectCollection
   Implements ICollection, IEnumerable, IDisposable
[C#]
public class ManagementObjectCollection : ICollection, IEnumerable,
   IDisposable
[C++]
public __gc class ManagementObjectCollection : public ICollection,
   IEnumerable, IDisposable
[JScript]
public class ManagementObjectCollection implements ICollection,
   IEnumerable, IDisposable

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.

Example

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

// This example demonstrates how to enumerate instances of a ManagementClass object.
class Sample_ManagementObjectCollection 
{ 
    public static int Main(string[] args) { 
        ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk");
        ManagementObjectCollection disks = diskClass.GetInstances(); 
        foreach (ManagementObject disk in disks) { 
            Console.WriteLine("Disk = " + disk["deviceid"]); 
        } 
        return 0;
    }
}
   
[Visual Basic] 
Imports System 
Imports System.Management 

' This example demonstrates how to enumerate instances of a ManagementClass object.
Class Sample_ManagementObjectCollection 
    Overloads Public Shared Function Main(args() As String) As Integer 
        Dim diskClass As New ManagementClass("Win32_LogicalDisk") 
        Dim disks As ManagementObjectCollection = diskClass.GetInstances()
        Dim disk As ManagementObject
        For Each disk In disks
            Console.WriteLine("Disk = " & disk("deviceid").ToString())
        Next disk
        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

ManagementObjectCollection Members | System.Management Namespace

Show:
© 2014 Microsoft