ManagementObject.Get Método

Definição

Associa ao objeto de gerenciamento.Binds to the management object.

Sobrecargas

Get()

Associa as informações de classe WMI ao objeto de gerenciamento.Binds WMI class information to the management object.

Get(ManagementOperationObserver)

Associa ao objeto de gerenciamento de forma assíncrona.Binds to the management object asynchronously.

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.

Get()

Associa as informações de classe WMI ao objeto de gerenciamento.Binds WMI class information to the management object.

public:
 void Get();
public void Get ();
member this.Get : unit -> unit
Public Sub Get ()

Exemplos

O exemplo a seguir chama o Get método para obter uma instância da ManagementObject classe.The following example calls the Get method to get an instance of the ManagementObject class.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        ManagementObject o =
            new ManagementObject("MyClass.Name='abc'");

        //this causes an implicit Get().
        string s = o["Name"].ToString();

        Console.WriteLine(s);

        //or :

        ManagementObject mObj =
            new ManagementObject("MyClass.Name= 'abc'");
        mObj.Get(); //explicitly
        // Now it is faster because the object
        // has already been retrieved.
        string property = mObj["Name"].ToString();

        Console.WriteLine(property);

        return 0;
    }
}
Imports System.Management

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

        Dim o As New ManagementObject( _
            "MyClass.Name=""abc""")

        'this causes an implicit Get().
        Dim s As String = o("SomeProperty")

        Console.WriteLine(s)

        'or :

        Dim mObj As New ManagementObject("MyClass.Name= ""abc""")
        mObj.Get()  'explicitly 
        ' Now it is faster because the object
        ' has already been retrieved.
        Dim p As String = mObj("SomeProperty")

        Console.WriteLine(p)

        Return 0
    End Function
End Class

Comentários

O método é invocado implicitamente na primeira tentativa de obter ou definir informações para o objeto WMI.The method is implicitly invoked at the first attempt to get or set information to the WMI object. Ele também pode ser invocado explicitamente a critério do usuário, para controlar melhor o tempo e a maneira de recuperação.It can also be explicitly invoked at the user's discretion, to better control the timing and manner of retrieval.

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

Get(ManagementOperationObserver)

Associa ao objeto de gerenciamento de forma assíncrona.Binds to the management object asynchronously.

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

Parâmetros

watcher
ManagementOperationObserver

O objeto a receber os resultados da operação como eventos.The object to receive the results of the operation as events.

Exemplos

O exemplo a seguir chama o Get método para obter uma instância da classe de forma assíncrona ManagementObject .The following example calls the Get method to asynchronously get an instance of the ManagementObject class.

using System;
using System.Management;

public class AsyncGetExample
{
    public AsyncGetExample()
    {
        ManagementObject o =
            new ManagementObject(
            "Win32_Process.Name='notepad.exe'");

        // Set up handlers for asynchronous get
        ManagementOperationObserver ob =
            new ManagementOperationObserver();
        ob.Completed += new
            CompletedEventHandler(this.Done);

        // Get the object asynchronously
        o.Get(ob);

        // Wait until operation is completed
        while (!this.Completed)
            System.Threading.Thread.Sleep (1000);

        // Here you can use the object
    }

    private bool completed = false;

    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 example =
            new AsyncGetExample();
    }
}
Imports System.Management

Class AsyncGetExample

    Public Sub New()

        Dim o As New ManagementObject( _
            "Win32_Process.Name=""notepad.exe""")

        'Set up handlers for asynchronous get
        Dim ob As New ManagementOperationObserver
        AddHandler ob.Completed, AddressOf Me.Done

        'Get the object asynchronously
        o.Get(ob)

        'Wait until operation is completed
        While Not Me.Completed
            System.Threading.Thread.Sleep(1000)
        End While

        'Here you can use the object

    End Sub

    Private _completed As Boolean = False

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

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

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

        Dim example As New AsyncGetExample

        Return 0

    End Function


End Class

Comentários

O método emitirá a solicitação para obter o objeto e, em seguida, retornará imediatamente.The method will issue the request to get the object and then will immediately return. Os resultados da operação serão então entregues por meio de eventos sendo acionados no objeto do Inspetor fornecido.The results of the operation will then be delivered through events being fired on the watcher object provided.

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