Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 GetInstances Method (EnumerationOpt...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ManagementClass..::.GetInstances Method (EnumerationOptions)

Returns the collection of all instances of the class using the specified options.

Namespace:  System.Management
Assembly:  System.Management (in System.Management.dll)
Visual Basic (Declaration)
Public Function GetInstances ( _
    options As EnumerationOptions _
) As ManagementObjectCollection
Visual Basic (Usage)
Dim instance As ManagementClass
Dim options As EnumerationOptions
Dim returnValue As ManagementObjectCollection

returnValue = instance.GetInstances(options)
C#
public ManagementObjectCollection GetInstances(
    EnumerationOptions options
)
Visual C++
public:
ManagementObjectCollection^ GetInstances(
    EnumerationOptions^ options
)
JScript
public function GetInstances(
    options : EnumerationOptions
) : ManagementObjectCollection

Parameters

options
Type: System.Management..::.EnumerationOptions
The additional operation options.

Return Value

Type: System.Management..::.ManagementObjectCollection
A collection of the ManagementObject objects representing the instances of the class, according to the specified options.

.NET Framework Security

Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

The following example shows how to initialize a ManagementClass variable with a ManagementClass constructor and then get all the instances of a WMI class and its subclasses.

Visual Basic
Imports System
Imports System.Management

Class Sample

    Public Overloads Shared Function _
    Main(ByVal args() As String) As Integer

        Dim opt As New EnumerationOptions
        ' Will enumerate instances of the given class and any subclasses.
        opt.EnumerateDeep = True
        Dim mngmtClass As New ManagementClass("CIM_Service")
        Dim o As ManagementObject
        For Each o In mngmtClass.GetInstances(opt)
            Console.WriteLine(o("Name"))
        Next o

    End Function
End Class

C#
using System;
using System.Management;

public class Sample 
{    
    public static void Main() 
    {
        EnumerationOptions opt = new EnumerationOptions();
        // Will enumerate instances of the given class and any subclasses.
        opt.EnumerateDeep = true;
        ManagementClass c = new ManagementClass("CIM_Service");
        foreach (ManagementObject o in c.GetInstances(opt))
            Console.WriteLine(o["Name"]);

    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker