ManagementClass.GetInstances Método

Definição

Retorna a coleção de todas as instâncias da classe.Returns the collection of all instances of the class.

Sobrecargas

GetInstances()

Retorna a coleção de todas as instâncias da classe.Returns the collection of all instances of the class.

GetInstances(EnumerationOptions)

Retorna a coleção de todas as instâncias da classe que usam as opções especificadas.Returns the collection of all instances of the class using the specified options.

GetInstances(ManagementOperationObserver)

Retorna a coleção de todas as instâncias da classe, de maneira assíncrona.Returns the collection of all instances of the class, asynchronously.

GetInstances(ManagementOperationObserver, EnumerationOptions)

Retorna a coleção de todas as instâncias da classe, de maneira assíncrona, usando as opções especificadas.Returns the collection of all instances of the class, asynchronously, using the specified options.

Comentários

Segurança do .NET Framework.NET Framework Security

Confiança total para o chamador imediato.Full trust for the immediate caller. Este membro não pode ser usado pelo código parcialmente confiável.This member cannot be used by partially trusted code. Para obter mais informações, consulte usando bibliotecas de código parcialmente confiável.For more information, see Using Libraries from Partially Trusted Code.

GetInstances()

Retorna a coleção de todas as instâncias da classe.Returns the collection of all instances of the class.

public:
 System::Management::ManagementObjectCollection ^ GetInstances();
public System.Management.ManagementObjectCollection GetInstances ();
member this.GetInstances : unit -> System.Management.ManagementObjectCollection
Public Function GetInstances () As ManagementObjectCollection

Retornos

ManagementObjectCollection

Uma coleção dos objetos ManagementObject que representam as instâncias da classe.A collection of the ManagementObject objects representing the instances of the class.

Exemplos

O exemplo a seguir mostra como inicializar uma ManagementClass variável com um ManagementClass Construtor e, em seguida, obter todas as instâncias de uma classe WMI.The following example shows how to initialize a ManagementClass variable with a ManagementClass constructor and then get all the instances of a WMI class.

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {
        ManagementClass c = new ManagementClass("Win32_Process");
        foreach (ManagementObject o in c.GetInstances())
            Console.WriteLine(
                "Next instance of Win32_Process : {0}", o["Name"]);
    }
}
Imports System.Management

Class Sample

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

        Dim c As New ManagementClass("Win32_Process")
        Dim o As ManagementObject
        For Each o In c.GetInstances()
            Console.WriteLine( _
                "Next instance of Win32_Process : {0}", o("Name"))
        Next o

    End Function
End Class

Comentários

Segurança do .NET Framework.NET Framework Security

Confiança total para o chamador imediato.Full trust for the immediate caller. Este membro não pode ser usado pelo código parcialmente confiável.This member cannot be used by partially trusted code. Para obter mais informações, consulte usando bibliotecas de código parcialmente confiável.For more information, see Using Libraries from Partially Trusted Code.

Aplica-se a

GetInstances(EnumerationOptions)

Retorna a coleção de todas as instâncias da classe que usam as opções especificadas.Returns the collection of all instances of the class using the specified options.

public:
 System::Management::ManagementObjectCollection ^ GetInstances(System::Management::EnumerationOptions ^ options);
public System.Management.ManagementObjectCollection GetInstances (System.Management.EnumerationOptions options);
member this.GetInstances : System.Management.EnumerationOptions -> System.Management.ManagementObjectCollection
Public Function GetInstances (options As EnumerationOptions) As ManagementObjectCollection

Parâmetros

options
EnumerationOptions

As opções de operação adicionais.The additional operation options.

Retornos

ManagementObjectCollection

Uma coleção dos objetos ManagementObject que representam as instâncias da classe, de acordo com as opções especificadas.A collection of the ManagementObject objects representing the instances of the class, according to the specified options.

Exemplos

O exemplo a seguir mostra como inicializar uma ManagementClass variável com um ManagementClass Construtor e, em seguida, obter todas as instâncias de uma classe WMI e suas subclasses.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.

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"]);
    }
}
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

Comentários

Segurança do .NET Framework.NET Framework Security

Confiança total para o chamador imediato.Full trust for the immediate caller. Este membro não pode ser usado pelo código parcialmente confiável.This member cannot be used by partially trusted code. Para obter mais informações, consulte usando bibliotecas de código parcialmente confiável.For more information, see Using Libraries from Partially Trusted Code.

Aplica-se a

GetInstances(ManagementOperationObserver)

Retorna a coleção de todas as instâncias da classe, de maneira assíncrona.Returns the collection of all instances of the class, asynchronously.

public:
 void GetInstances(System::Management::ManagementOperationObserver ^ watcher);
public void GetInstances (System.Management.ManagementOperationObserver watcher);
member this.GetInstances : System.Management.ManagementOperationObserver -> unit
Public Sub GetInstances (watcher As ManagementOperationObserver)

Parâmetros

watcher
ManagementOperationObserver

O objeto para controlar o progresso da operação assíncrona.The object to handle the asynchronous operation's progress.

Exemplos

O exemplo a seguir mostra como inicializar uma ManagementClass variável com um ManagementClass Construtor e, em seguida, obter todas as instâncias de uma classe WMI de forma assíncrona.The following example shows how to initialize a ManagementClass variable with a ManagementClass constructor and then get all the instances of a WMI class asynchronously.

using System;
using System.Management;

public class AsyncGetExample
{
    public AsyncGetExample()
    {
        ManagementClass c =
            new ManagementClass("Win32_Process");
        ManagementOperationObserver ob =
            new ManagementOperationObserver();
        ob.ObjectReady += new ObjectReadyEventHandler(NewObject);
        ob.Completed += new CompletedEventHandler(Done);

        c.GetInstances(ob);

        while (!Completed)
            System.Threading.Thread.Sleep (1000);

        // Here you can use the object
    }

    private bool completed = false;

    private void NewObject(object sender,
        ObjectReadyEventArgs e)
    {
        Console.WriteLine("New result arrived: {0}",
            ((ManagementObject)(e.NewObject))["Name"]);
    }

    private void Done(object sender,
        CompletedEventArgs e)
    {
        Console.WriteLine("async Get completed !");
        completed = true;
    }

    private bool Completed
    {
        get
        {
            return completed;
        }
    }

    public static void Main()
    {
        AsyncGetExample asyncGet = new
            AsyncGetExample();

        return;
    }
}
Imports System.Management

Public Class AsyncGetExample

    Public Sub New()

        Dim c As New ManagementClass("Win32_Process")
        Dim ob As New ManagementOperationObserver
        AddHandler ob.ObjectReady, AddressOf Me.NewObject
        AddHandler ob.Completed, AddressOf Me.Done

        c.GetInstances(ob)

        While Not Me.Completed
            System.Threading.Thread.Sleep(1000)
        End While

        'Here you can use the object

    End Sub

    Private finished As Boolean = False

    Private Sub NewObject(ByVal sender As Object, _
    ByVal e As ObjectReadyEventArgs)
        Console.WriteLine("New result arrived: {0}", _
         e.NewObject("Name"))
    End Sub

    Private Sub Done(ByVal sender As Object, _
    ByVal e As CompletedEventArgs)
        Console.WriteLine("async Get completed !")
        finished = True
    End Sub

    Private ReadOnly Property Completed() As Boolean
        Get
            Return finished
        End Get
    End Property


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

        Dim asyncGet As New AsyncGetExample

        Return 0

    End Function

End Class

Comentários

Segurança do .NET Framework.NET Framework Security

Confiança total para o chamador imediato.Full trust for the immediate caller. Este membro não pode ser usado pelo código parcialmente confiável.This member cannot be used by partially trusted code. Para obter mais informações, consulte usando bibliotecas de código parcialmente confiável.For more information, see Using Libraries from Partially Trusted Code.

Aplica-se a

GetInstances(ManagementOperationObserver, EnumerationOptions)

Retorna a coleção de todas as instâncias da classe, de maneira assíncrona, usando as opções especificadas.Returns the collection of all instances of the class, asynchronously, using the specified options.

public:
 void GetInstances(System::Management::ManagementOperationObserver ^ watcher, System::Management::EnumerationOptions ^ options);
public void GetInstances (System.Management.ManagementOperationObserver watcher, System.Management.EnumerationOptions options);
member this.GetInstances : System.Management.ManagementOperationObserver * System.Management.EnumerationOptions -> unit
Public Sub GetInstances (watcher As ManagementOperationObserver, options As EnumerationOptions)

Parâmetros

watcher
ManagementOperationObserver

O objeto para controlar o progresso da operação assíncrona.The object to handle the asynchronous operation's progress.

options
EnumerationOptions

As opções adicionais especificadas para obter as instâncias.The specified additional options for getting the instances.

Comentários

Segurança do .NET Framework.NET Framework Security

Confiança total para o chamador imediato.Full trust for the immediate caller. Este membro não pode ser usado pelo código parcialmente confiável.This member cannot be used by partially trusted code. Para obter mais informações, consulte usando bibliotecas de código parcialmente confiável.For more information, see Using Libraries from Partially Trusted Code.

Aplica-se a