ManagementObject Constructors

Definition

Initializes a new instance of the ManagementObject class.

Overloads

ManagementObject()

Initializes a new instance of the ManagementObject class. This is the parameterless constructor.

ManagementObject(ManagementPath)

Initializes a new instance of the ManagementObject class for the specified WMI object path. The path is provided as a ManagementPath.

ManagementObject(String)

Initializes a new instance of the ManagementObject class for the specified WMI object path. The path is provided as a string.

ManagementObject(ManagementPath, ObjectGetOptions)

Initializes a new instance of the ManagementObject class bound to the specified WMI path, including the specified additional options.

ManagementObject(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the ManagementObject class that is serializable.

ManagementObject(String, ObjectGetOptions)

Initializes a new instance of the ManagementObject class bound to the specified WMI path, including the specified additional options. In this variant, the path can be specified as a string.

ManagementObject(ManagementScope, ManagementPath, ObjectGetOptions)

Initializes a new instance of the ManagementObject class bound to the specified WMI path that includes the specified options.

ManagementObject(String, String, ObjectGetOptions)

Initializes a new instance of the ManagementObject class bound to the specified WMI path, and includes the specified options. The scope and the path are specified as strings.

ManagementObject()

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

Initializes a new instance of the ManagementObject class. This is the parameterless constructor.

public:
 ManagementObject();
public ManagementObject ();
Public Sub New ()

Examples

The following example initializes a new instance of the ManagementObject class with the parameterless constructor.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        ManagementObject o = new ManagementObject();

        // Now set the path on this object to
        // bind it to a 'real' manageable entity
        o.Path =
            new ManagementPath("Win32_LogicalDisk='c:'");

        //Now it can be used
        Console.WriteLine(o["FreeSpace"]);

        return 0;
    }
}
Imports System.Management

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

        Dim o As New ManagementObject

        Dim mp As New _
            ManagementPath("Win32_LogicalDisk='c:'")

        ' Now set the path on this object to
        ' bind it to a 'real' manageable entity
        o.Path = mp

        'Now it can be used 
        Console.WriteLine(o("FreeSpace"))

        Return 0
    End Function
End Class

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.

Applies to

ManagementObject(ManagementPath)

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

Initializes a new instance of the ManagementObject class for the specified WMI object path. The path is provided as a ManagementPath.

public:
 ManagementObject(System::Management::ManagementPath ^ path);
public ManagementObject (System.Management.ManagementPath path);
new System.Management.ManagementObject : System.Management.ManagementPath -> System.Management.ManagementObject
Public Sub New (path As ManagementPath)

Parameters

path
ManagementPath

A ManagementPath that contains a path to a WMI object.

Examples

The following example initializes a new instance of the ManagementObject class with a specified WMI object path.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        ManagementPath p =
            new ManagementPath(
            "Win32_Service.Name='Alerter'");
        ManagementObject o = new ManagementObject(p);

        //Now it can be used
        Console.WriteLine(o["Name"]);

        return 0;
    }
}
Imports System.Management

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

        Dim p As New ManagementPath( _
            "Win32_Service.Name=""Alerter""")
        Dim o As New ManagementObject(p)

        'Now it can be used 
        Console.WriteLine(o("Name"))

        Return 0
    End Function
End Class

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.

Applies to

ManagementObject(String)

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

Initializes a new instance of the ManagementObject class for the specified WMI object path. The path is provided as a string.

public:
 ManagementObject(System::String ^ path);
public ManagementObject (string path);
new System.Management.ManagementObject : string -> System.Management.ManagementObject
Public Sub New (path As String)

Parameters

path
String

A WMI path.

Examples

The following example initializes a new instance of the ManagementObject class.

using System;
using System.Management;

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

        //or with a full path :

        ManagementObject mObj =
            new ManagementObject(
            "\\\\MyServer\\root\\MyApp:MyClass.Key='abc'");

        return 0;
    }
}
Imports System.Management

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

        Dim o As New ManagementObject( _
    "Win32_Service.Name=""Alerter""")

        ' or with a full path :

        Dim mObj As New ManagementObject( _
            "\\\\MyServer\\root\\MyApp:MyClass.Key=""abc""")

        Return 0
    End Function
End Class

Remarks

If the specified path is a relative path only (a server or namespace is not specified), the default path is the local machine, and the default namespace is the DefaultPath path (by default, root\cimv2). If the user specifies a full path, the default settings are overridden.

.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

ManagementObject(ManagementPath, ObjectGetOptions)

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

Initializes a new instance of the ManagementObject class bound to the specified WMI path, including the specified additional options.

public:
 ManagementObject(System::Management::ManagementPath ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementObject (System.Management.ManagementPath path, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : System.Management.ManagementPath * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (path As ManagementPath, options As ObjectGetOptions)

Parameters

path
ManagementPath

A ManagementPath containing the WMI path.

options
ObjectGetOptions

An ObjectGetOptions containing additional options for binding to the WMI object. This parameter could be null if default options are to be used.

Examples

The following example initializes a new instance of the ManagementObject class that is bound to a specific WMI path.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        ManagementPath p =
            new ManagementPath("Win32_Service");

        // Set options for no context info
        // but requests amended qualifiers
        // to be contained in the object
        ObjectGetOptions opt =
            new ObjectGetOptions(
            null, System.TimeSpan.MaxValue, true);

        ManagementClass c =
            new ManagementClass(p, opt);

        Console.WriteLine(
            c.Qualifiers["Description"].Value);

        return 0;
    }
}
Imports System.Management

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

        Dim p As New ManagementPath("Win32_Service")

        ' Set options for no context info
        ' but requests amended qualifiers 
        ' to be contained in the object
        Dim opt As New ObjectGetOptions( _
            Nothing, TimeSpan.MaxValue, True)

        Dim c As New ManagementClass(p, opt)

        Console.WriteLine(c.Qualifiers("Description").Value)

        Return 0
    End Function
End Class

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.

Applies to

ManagementObject(SerializationInfo, StreamingContext)

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

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the ManagementObject class that is serializable.

protected:
 ManagementObject(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
public:
 ManagementObject(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected ManagementObject (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected ManagementObject (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
public ManagementObject (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Management.ManagementObject : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementObject
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Management.ManagementObject : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementObject
Protected Sub New (info As SerializationInfo, context As StreamingContext)
Public Sub New (info As SerializationInfo, context As StreamingContext)

Parameters

info
SerializationInfo

The SerializationInfo to populate with data.

context
StreamingContext

The destination (see StreamingContext) for this serialization.

Attributes

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.

Applies to

ManagementObject(String, ObjectGetOptions)

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

Initializes a new instance of the ManagementObject class bound to the specified WMI path, including the specified additional options. In this variant, the path can be specified as a string.

public:
 ManagementObject(System::String ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementObject (string path, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : string * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (path As String, options As ObjectGetOptions)

Parameters

path
String

The WMI path to the object.

options
ObjectGetOptions

An ObjectGetOptions representing options to get the specified WMI object.

Examples

The following example initializes a new instance of the ManagementObject class.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        // Set options for no context info,
        // but requests amended qualifiers
        // to be contained in the object
        ObjectGetOptions opt =
            new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);

        ManagementObject o =
            new ManagementObject(
            "Win32_Service", opt);

        Console.WriteLine(o.GetQualifierValue("Description"));

        return 0;
    }
}
Imports System.Management

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

        ' Set options for no context info, 
        ' but requests amended qualifiers
        ' to be contained in the object
        Dim opt As New ObjectGetOptions( _
            Nothing, System.TimeSpan.MaxValue, True)

        Dim o As New ManagementObject( _
            "Win32_Service", opt)

        Console.WriteLine(o.GetQualifierValue("Description"))

        Return 0
    End Function
End Class

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.

Applies to

ManagementObject(ManagementScope, ManagementPath, ObjectGetOptions)

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

Initializes a new instance of the ManagementObject class bound to the specified WMI path that includes the specified options.

public:
 ManagementObject(System::Management::ManagementScope ^ scope, System::Management::ManagementPath ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementObject (System.Management.ManagementScope scope, System.Management.ManagementPath path, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : System.Management.ManagementScope * System.Management.ManagementPath * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (scope As ManagementScope, path As ManagementPath, options As ObjectGetOptions)

Parameters

scope
ManagementScope

A ManagementScope representing the scope in which the WMI object resides. In this version, scopes can only be WMI namespaces.

path
ManagementPath

A ManagementPath representing the WMI path to the manageable object.

options
ObjectGetOptions

An ObjectGetOptions specifying additional options for getting the object.

Examples

The following example initializes a new instance of the ManagementObject class that is bound to a specific WMI path.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        ManagementScope s = new ManagementScope(
            "\\\\MyMachine\\root\\cimv2");
        ManagementPath p =
            new ManagementPath(
            "Win32_Service");

        // Set options for no context info,
        // but requests amended qualifiers
        // to be contained in the object
        ObjectGetOptions opt =
            new ObjectGetOptions(
            null, TimeSpan.MaxValue, true);

        ManagementObject o = new ManagementObject(s, p, opt);

        Console.WriteLine(o.Qualifiers["Description"].Value);

        return 0;
    }
}
Imports System.Management

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

        Dim s As New ManagementScope( _
            "\\MyMachine\root\cimv2")
        Dim p As New ManagementPath( _
            "Win32_Service")

        ' Set options for no context info,
        ' but requests amended qualifiers 
        ' to be contained in the object
        Dim opt As ObjectGetOptions
        opt = New ObjectGetOptions( _
                Nothing, TimeSpan.MaxValue, True)

        Dim o As ManagementObject
        o = New ManagementObject(s, p, opt)

        Console.WriteLine(o.Qualifiers("Description").Value)

        Return 0
    End Function
End Class

Remarks

Because WMI paths can be relative or full, a conflict between the scope and the path specified may arise. However, if a scope is specified and a relative WMI path is specified, then there is no conflict. The following are some possible conflicts:

If a scope is not specified and a relative WMI path is specified, then the scope will default to the local machine's DefaultPath.

If a scope is not specified and a full WMI path is specified, then the scope will be inferred from the scope portion of the full path. For example, the full WMI path: \\MyMachine\root\MyNamespace:MyClass.Name='abc' will represent the WMI object 'MyClass.Name='abc'" in the scope '\\MyMachine\root\MyNamespace'.

If a scope is specified and a full WMI path is specified, then the scope will override the scope portion of the full path. For example, if the following scope was specified: \\MyMachine\root\MyScope, and the following full path was specified: \\MyMachine\root\MyNamespace:MyClass.Name='abc', then look for the following object: \\MyMachine\root\MyScope:MyClass.Name= 'abc' (the scope part of the full path is ignored).

.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

ManagementObject(String, String, ObjectGetOptions)

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

Initializes a new instance of the ManagementObject class bound to the specified WMI path, and includes the specified options. The scope and the path are specified as strings.

public:
 ManagementObject(System::String ^ scopeString, System::String ^ pathString, System::Management::ObjectGetOptions ^ options);
public ManagementObject (string scopeString, string pathString, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : string * string * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (scopeString As String, pathString As String, options As ObjectGetOptions)

Parameters

scopeString
String

The scope for the WMI object.

pathString
String

The WMI object path.

options
ObjectGetOptions

An ObjectGetOptions representing additional options for getting the WMI object.

Examples

The following example initializes a new instance of the ManagementObject class with a specific WMI path and options.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        ObjectGetOptions opt =
            new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);
        ManagementObject o =
            new ManagementObject(
            "root\\MyNamespace", "MyClass", opt);

        return 0;
    }
}
Imports System.Management

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

        Dim opt As New ObjectGetOptions( _
            Nothing, System.TimeSpan.MaxValue, True)
        Dim o As New ManagementObject( _
            "root\MyNamespace", "MyClass", opt)

        Return 0
    End Function
End Class

Remarks

See the equivalent overload for details.

.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