Export (0) Print
Expand All

ManagementObjectCollection.ManagementObjectEnumerator Class

Represents the enumerator on the collection.


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

Public Class ManagementObjectEnumerator _
	Implements IEnumerator, IDisposable

The ManagementObjectCollection.ManagementObjectEnumerator type exposes the following members.

Public propertyCurrentGets the current ManagementBaseObject that this enumerator points to.

Public methodDisposeReleases resources associated with this object. After this method has been called, an attempt to use this object will result in an ObjectDisposedException exception being thrown.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeDisposes of resources the object is holding. This is the destructor for the object. Finalizers are expressed using destructor syntax. (Overrides Object.Finalize.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodMoveNextIndicates whether the enumerator has moved to the next object in the enumeration.
Public methodResetResets the enumerator to the beginning of the collection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Explicit interface implemetationPrivate propertyIEnumerator.CurrentGets the current object in the collection.

The following example enumerates through all of the instances of the Win32_LogicalDisk class, and displays the DeviceID value for each instance.

Imports System
Imports System.Management

' This sample demonstrates how to 
' enumerate all logical disks 
' using ManagementObjectEnumerator object. 
Class Sample_ManagementObjectEnumerator
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer 
        Dim diskClass As New _
        Dim disks As ManagementObjectCollection = _
        Dim disksEnumerator As _
        ManagementObjectCollection. _
            ManagementObjectEnumerator = _
        While disksEnumerator.MoveNext()
            Dim disk As ManagementObject = _
            CType(disksEnumerator.Current, _
            Console.WriteLine("Disk found: " & disk("deviceid"))
        End While 
        Return 0
    End Function 
End Class

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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