Udostępnij przez


ManagementClass.GetInstances Metoda

Definicja

Zwraca kolekcję wszystkich wystąpień klasy.

Przeciążenia

GetInstances()

Zwraca kolekcję wszystkich wystąpień klasy.

GetInstances(EnumerationOptions)

Zwraca kolekcję wszystkich wystąpień klasy przy użyciu określonych opcji.

GetInstances(ManagementOperationObserver)

Zwraca kolekcję wszystkich wystąpień klasy asynchronicznie.

GetInstances(ManagementOperationObserver, EnumerationOptions)

Zwraca kolekcję wszystkich wystąpień klasy asynchronicznie przy użyciu określonych opcji.

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

GetInstances()

Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs

Zwraca kolekcję wszystkich wystąpień klasy.

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

Zwraca

Kolekcja ManagementObject obiektów reprezentujących wystąpienia klasy.

Przykłady

W poniższym przykładzie pokazano, jak zainicjować zmienną ManagementClass za pomocą konstruktora ManagementClass , a następnie pobrać wszystkie wystąpienia klasy WMI.

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

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

GetInstances(EnumerationOptions)

Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs

Zwraca kolekcję wszystkich wystąpień klasy przy użyciu określonych opcji.

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

Parametry

options
EnumerationOptions

Dodatkowe opcje operacji.

Zwraca

Kolekcja ManagementObject obiektów reprezentujących wystąpienia klasy zgodnie z określonymi opcjami.

Przykłady

W poniższym przykładzie pokazano, jak zainicjować zmienną ManagementClass za pomocą ManagementClass konstruktora, a następnie pobrać wszystkie wystąpienia klasy WMI i jej podklasy.

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

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

GetInstances(ManagementOperationObserver)

Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs

Zwraca kolekcję wszystkich wystąpień klasy asynchronicznie.

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)

Parametry

watcher
ManagementOperationObserver

Obiekt obsługujący postęp operacji asynchronicznej.

Przykłady

W poniższym przykładzie pokazano, jak zainicjować zmienną ManagementClass za pomocą ManagementClass konstruktora, a następnie pobrać wszystkie wystąpienia klasy WMI asynchronicznie.

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

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

GetInstances(ManagementOperationObserver, EnumerationOptions)

Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs
Źródło:
ManagementClass.cs

Zwraca kolekcję wszystkich wystąpień klasy asynchronicznie przy użyciu określonych opcji.

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)

Parametry

watcher
ManagementOperationObserver

Obiekt obsługujący postęp operacji asynchronicznej.

options
EnumerationOptions

Określone dodatkowe opcje pobierania wystąpień.

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy