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
Dim instance As ManagementClass
Dim options As EnumerationOptions
Dim returnValue As ManagementObjectCollection
returnValue = instance.GetInstances(options)
public ManagementObjectCollection GetInstances(
EnumerationOptions options
)
public:
ManagementObjectCollection^ GetInstances(
EnumerationOptions^ options
)
public function GetInstances(
options : EnumerationOptions
) : ManagementObjectCollection
.NET Framework Security
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.
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
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
Reference