ManagementObject.Get Method

Definition

Binds to the management object.

Overloads

Get()

Binds WMI class information to the management object.

Get(ManagementOperationObserver)

Binds to the management object asynchronously.

Remarks

.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.

Get()

Source:
ManagementObject.cs
Source:
ManagementObject.cs
Source:
ManagementObject.cs

Binds WMI class information to the management object.

C#
public void Get();

Examples

The following example calls the Get method to get an instance of the ManagementObject class.

C#
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;
    }
}

Remarks

The method is implicitly invoked at the first attempt to get or set information to the WMI object. It can also be explicitly invoked at the user's discretion, to better control the timing and manner of retrieval.

.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.

Applies to

.NET 10 (package-provided) i inne wersje
Produkt Wersje
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Get(ManagementOperationObserver)

Source:
ManagementObject.cs
Source:
ManagementObject.cs
Source:
ManagementObject.cs

Binds to the management object asynchronously.

C#
public void Get(System.Management.ManagementOperationObserver watcher);

Parameters

watcher
ManagementOperationObserver

The object to receive the results of the operation as events.

Examples

The following example calls the Get method to asynchronously get an instance of the ManagementObject class.

C#
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();
    }
}

Remarks

The method will issue the request to get the object and then will immediately return. The results of the operation will then be delivered through events being fired on the watcher object provided.

.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.

Applies to

.NET 10 (package-provided) i inne wersje
Produkt Wersje
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)