Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

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)
public class ManagementObjectEnumerator : 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 a hash function for a particular type. (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.


using System; 
using System.Management;

// This example demonstrates how to
// enumerate all logical disks 
// using the ManagementObjectEnumerator object.
class Sample_ManagementObjectEnumerator 
{
    public static int Main(string[] args) 
    { 
        ManagementClass diskClass = 
            new ManagementClass("Win32_LogicalDisk");
        ManagementObjectCollection disks = 
            diskClass.GetInstances();
        ManagementObjectCollection.ManagementObjectEnumerator
            disksEnumerator =
            disks.GetEnumerator();
        while(disksEnumerator.MoveNext()) 
        { 
            ManagementObject disk = 
                (ManagementObject)disksEnumerator.Current;
            Console.WriteLine(
                "Disk found: " + disk["deviceid"]);
        }
        return 0;
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.