ManagementObject 构造函数

定义

初始化 ManagementObject 类的新实例。

重载

名称 说明
ManagementObject()

初始化 ManagementObject 类的新实例。 这是无参数构造函数。

ManagementObject(ManagementPath)

为指定的 WMI 对象路径初始化类的新实例 ManagementObject 。 路径以 ManagementPath.

ManagementObject(String)

为指定的 WMI 对象路径初始化类的新实例 ManagementObject 。 路径以字符串的形式提供。

ManagementObject(ManagementPath, ObjectGetOptions)

初始化绑定到指定 WMI 路径的 ManagementObject 类的新实例,包括指定的附加选项。

ManagementObject(SerializationInfo, StreamingContext)
已过时.

初始化可序列化的 ManagementObject 类的新实例。

ManagementObject(String, ObjectGetOptions)

初始化绑定到指定 WMI 路径的 ManagementObject 类的新实例,包括指定的附加选项。 在此变体中,可以将路径指定为字符串。

ManagementObject(ManagementScope, ManagementPath, ObjectGetOptions)

初始化绑定到指定 WMI 路径( ManagementObject 包括指定选项)的类的新实例。

ManagementObject(String, String, ObjectGetOptions)

初始化绑定到指定 WMI 路径的 ManagementObject 类的新实例,并包括指定的选项。 范围和路径指定为字符串。

ManagementObject()

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

初始化 ManagementObject 类的新实例。 这是无参数构造函数。

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

示例

以下示例使用无参数构造函数初始化类的新实例 ManagementObject

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

注解

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于

ManagementObject(ManagementPath)

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

为指定的 WMI 对象路径初始化类的新实例 ManagementObject 。 路径以 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)

参数

path
ManagementPath

包含 WMI 对象的路径的 A ManagementPath

示例

以下示例使用指定的 WMI 对象路径初始化类的新实例 ManagementObject

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

注解

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于

ManagementObject(String)

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

为指定的 WMI 对象路径初始化类的新实例 ManagementObject 。 路径以字符串的形式提供。

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

参数

path
String

WMI 路径。

示例

以下示例初始化类的新实例 ManagementObject

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

注解

如果指定的路径只是相对路径(未指定服务器或命名空间),则默认路径是本地计算机,默认命名空间是 DefaultPath 路径(默认情况下为 root\cimv2)。 如果用户指定完整路径,则重写默认设置。

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于

ManagementObject(ManagementPath, ObjectGetOptions)

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

初始化绑定到指定 WMI 路径的 ManagementObject 类的新实例,包括指定的附加选项。

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)

参数

path
ManagementPath

包含 WMI 路径的 A ManagementPath

options
ObjectGetOptions

包含 ObjectGetOptions 用于绑定到 WMI 对象的附加选项。 如果使用默认选项,则此参数可以为 null。

示例

以下示例初始化绑定到特定 WMI 路径的 ManagementObject 类的新实例。

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

注解

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于

ManagementObject(SerializationInfo, StreamingContext)

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

注意

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

初始化可序列化的 ManagementObject 类的新实例。

protected:
 ManagementObject(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
public:
 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);
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}")>]
new System.Management.ManagementObject : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementObject
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)

参数

info
SerializationInfo

SerializationInfo 填充数据。

context
StreamingContext

此序列化的目标(请参阅 StreamingContext)。

属性

注解

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于

ManagementObject(String, ObjectGetOptions)

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

初始化绑定到指定 WMI 路径的 ManagementObject 类的新实例,包括指定的附加选项。 在此变体中,可以将路径指定为字符串。

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)

参数

path
String

对象的 WMI 路径。

options
ObjectGetOptions

用于 ObjectGetOptions 获取指定 WMI 对象的表示选项。

示例

以下示例初始化类的新实例 ManagementObject

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

注解

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于

ManagementObject(ManagementScope, ManagementPath, ObjectGetOptions)

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

初始化绑定到指定 WMI 路径( ManagementObject 包括指定选项)的类的新实例。

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)

参数

scope
ManagementScope

一个 ManagementScope 表示 WMI 对象所在的范围。 在此版本中,范围只能是 WMI 命名空间。

path
ManagementPath

一个 ManagementPath 表示可管理对象的 WMI 路径。

options
ObjectGetOptions

指定 ObjectGetOptions 用于获取对象的其他选项。

示例

以下示例初始化绑定到特定 WMI 路径的 ManagementObject 类的新实例。

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

注解

由于 WMI 路径可以是相对路径或完整路径,因此可能会出现范围与指定路径之间的冲突。 但是,如果指定了范围并指定了相对 WMI 路径,则不会发生冲突。 下面是一些可能的冲突:

如果未指定作用域,并且指定了相对 WMI 路径,则该范围将默认为本地计算机的 DefaultPath

如果未指定范围并指定完整的 WMI 路径,则会从完整路径的范围部分推断范围。 例如,完整的 WMI 路径: \\MyMachine\root\MyNamespace:MyClass.Name='abc' 将表示范围“\\MyMachine\root\MyNamespace”中的 WMI 对象“MyClass.Name='abc”。

如果指定了范围并指定了完整的 WMI 路径,则范围将覆盖完整路径的范围部分。 例如,如果指定了以下范围:\\MyMachine\root\MyScope,并且指定了以下完整路径:\\MyMachine\root\MyNamespace:MyClass.Name='abc',则查找以下内容 object: \\MyMachine\root\MyScope:MyClass.Name= 'abc' (忽略完整路径的范围部分)。

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于

ManagementObject(String, String, ObjectGetOptions)

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

初始化绑定到指定 WMI 路径的 ManagementObject 类的新实例,并包括指定的选项。 范围和路径指定为字符串。

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)

参数

scopeString
String

WMI 对象的作用域。

pathString
String

WMI 对象路径。

options
ObjectGetOptions

表示 ObjectGetOptions 用于获取 WMI 对象的其他选项。

示例

以下示例使用特定的 WMI 路径和选项初始化类的新实例 ManagementObject

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

注解

有关详细信息,请参阅等效重载。

.NET Framework 安全性

直接调用方完全信任。 此成员不能由部分受信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码的库

适用于