Export (0) Print
Expand All

ManagementObjectCollection.ManagementObjectEnumerator Class

Represents the enumerator on the collection.

System.Object
  System.Management.ManagementObjectCollection.ManagementObjectEnumerator

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

'Declaration
Public Class ManagementObjectEnumerator _
	Implements IEnumerator, IDisposable

The ManagementObjectCollection.ManagementObjectEnumerator type exposes the following members.

  NameDescription
Public propertyCurrentGets the current ManagementBaseObject that this enumerator points to.
Top

  NameDescription
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.)
Top

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

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 _
            ManagementClass("Win32_LogicalDisk")
        Dim disks As ManagementObjectCollection = _
            diskClass.GetInstances()
        Dim disksEnumerator As _
        ManagementObjectCollection. _
            ManagementObjectEnumerator = _
            disks.GetEnumerator()
        While disksEnumerator.MoveNext()
            Dim disk As ManagementObject = _
            CType(disksEnumerator.Current, _
                ManagementObject)
            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.
Show:
© 2015 Microsoft