ManagementClass 构造函数

定义

初始化 ManagementClass 类的新实例。

重载

ManagementClass()

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

ManagementClass(ManagementPath)

初始化 ManagementClass 类的新实例。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

ManagementClass(String)

初始化 ManagementClass 类的一个新实例,将其初始化到给定路径。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

ManagementClass(ManagementPath, ObjectGetOptions)

使用指定选项初始化 ManagementClass 类的一个新实例,将其初始化到给定的 WMI 类路径。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

ManagementClass(SerializationInfo, StreamingContext)
已过时.

ManagementClassSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。

ManagementClass(String, ObjectGetOptions)

使用指定选项初始化 ManagementClass 类的一个新实例,将其初始化到给定的 WMI 类路径。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

ManagementClass(ManagementScope, ManagementPath, ObjectGetOptions)

在指定的范围内,使用指定选项为指定的 WMI 类初始化 ManagementClass 类的一个新实例。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

ManagementClass(String, String, ObjectGetOptions)

在指定的范围内,使用指定选项为指定的 WMI 类初始化 ManagementClass 类的新实例。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

注解

.NET Framework 安全性

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

ManagementClass()

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

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

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

示例

以下示例演示如何使用ManagementClass无参数构造函数初始化ManagementClass变量。 该示例列出了所创建类的方法、属性和限定符。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class
        ManagementClass processClass =
            new ManagementClass();
        processClass.Path = new
            ManagementPath("Win32_Process");

        // Get the methods in the class
        MethodDataCollection methods =
            processClass.Methods;

        // display the methods
        Console.WriteLine("Method Names: ");
        foreach (MethodData method in methods)
        {
            Console.WriteLine(method.Name);
        }
        Console.WriteLine();

        // Get the properties in the class
        PropertyDataCollection properties =
            processClass.Properties;

        // display the properties
        Console.WriteLine("Property Names: ");
        foreach (PropertyData property in properties)
        {
            Console.WriteLine(property.Name);
        }
        Console.WriteLine();

        // Get the Qualifiers in the class
        QualifierDataCollection qualifiers =
            processClass.Qualifiers;

        // display the qualifiers
        Console.WriteLine("Qualifier Names: ");
        foreach (QualifierData qualifier in qualifiers)
        {
            Console.WriteLine(qualifier.Name);
        }
    }
}
Imports System.Management


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

        ' Get the WMI class
        Dim processClass As New ManagementClass
        processClass.Path = New _
            ManagementPath("Win32_Process")

        ' Get the methods in the class
        Dim methods As MethodDataCollection
        methods = processClass.Methods

        ' display the methods
        Console.WriteLine("Method Names: ")
        For Each method As MethodData In methods

            Console.WriteLine(method.Name)
        Next
        Console.WriteLine()

        ' Get the properties in the class
        Dim properties As PropertyDataCollection
        properties = processClass.Properties

        ' display the properties
        Console.WriteLine("Property Names: ")
        For Each p As PropertyData In properties

            Console.WriteLine(p.Name)
        Next
        Console.WriteLine()

        ' Get the Qualifiers in the class
        Dim qualifiers As QualifierDataCollection = _
        processClass.Qualifiers()

        ' display the qualifiers
        Console.WriteLine("Qualifier Names: ")
        For Each qualifier As QualifierData In qualifiers

            Console.WriteLine(qualifier.Name)
        Next

    End Function
End Class

注解

.NET Framework 安全性

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

适用于

ManagementClass(ManagementPath)

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

初始化 ManagementClass 类的新实例。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

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

参数

path
ManagementPath

ManagementPath,它指定要绑定到哪个 WMI 类。 参数必须指定一个 WMI 类路径。 该类表示 WMI 中的一个 CIM 管理类。 CIM 类表示包括硬件、软件、进程等在内的管理信息。 有关 Windows 中可用的 CIM 类的详细信息,请参阅 CIM 类

示例

以下示例演示如何使用ManagementClass构造函数初始化ManagementClass变量。 该示例列出了所创建类的方法、属性和限定符。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class
        ManagementClass c = new ManagementClass(
            new ManagementPath("Win32_LogicalDisk"));

        // Get the methods in the class
        MethodDataCollection methods =
            c.Methods;

        // display the methods
        Console.WriteLine("Method Names: ");
        foreach (MethodData method in methods)
        {
            Console.WriteLine(method.Name);
        }
        Console.WriteLine();

        // Get the properties in the class
        PropertyDataCollection properties =
            c.Properties;

        // display the properties
        Console.WriteLine("Property Names: ");
        foreach (PropertyData property in properties)
        {
            Console.WriteLine(property.Name);
        }
        Console.WriteLine();

        // Get the Qualifiers in the class
        QualifierDataCollection qualifiers =
            c.Qualifiers;

        // display the qualifiers
        Console.WriteLine("Qualifier Names: ");
        foreach (QualifierData qualifier in qualifiers)
        {
            Console.WriteLine(qualifier.Name);
        }
    }
}
Imports System.Management


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

        ' Get the WMI class
        Dim c As New ManagementClass( _
            New ManagementPath("Win32_LogicalDisk"))


        ' Get the methods in the class
        Dim methods As MethodDataCollection
        methods = c.Methods

        ' display the methods
        Console.WriteLine("Method Names: ")
        For Each method As MethodData In methods

            Console.WriteLine(method.Name)
        Next
        Console.WriteLine()

        ' Get the properties in the class
        Dim properties As PropertyDataCollection
        properties = c.Properties

        ' display the properties
        Console.WriteLine("Property Names: ")
        For Each p As PropertyData In properties

            Console.WriteLine(p.Name)
        Next
        Console.WriteLine()

        ' Get the Qualifiers in the class
        Dim qualifiers As QualifierDataCollection = _
        c.Qualifiers()

        ' display the qualifiers
        Console.WriteLine("Qualifier Names: ")
        For Each qualifier As QualifierData In qualifiers

            Console.WriteLine(qualifier.Name)
        Next

    End Function
End Class

注解

参数 path 必须指定 WMI 类路径。

.NET Framework 安全性

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

适用于

ManagementClass(String)

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

初始化 ManagementClass 类的一个新实例,将其初始化到给定路径。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

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

参数

path
String

WMI 类的路径。 该类表示 WMI 中的一个 CIM 管理类。 CIM 类表示包括硬件、软件、进程等在内的管理信息。 有关 Windows 中可用的 CIM 类的详细信息,请参阅 CIM 类

示例

以下示例演示如何使用ManagementClass构造函数初始化ManagementClass变量。 该示例列出了所创建类的方法、属性和限定符。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class
        ManagementClass c =
            new ManagementClass("Win32_LogicalDisk");

        // Get the methods in the class
        MethodDataCollection methods =
            c.Methods;

        // display the methods
        Console.WriteLine("Method Names: ");
        foreach (MethodData method in methods)
        {
            Console.WriteLine(method.Name);
        }
        Console.WriteLine();

        // Get the properties in the class
        PropertyDataCollection properties =
            c.Properties;

        // display the properties
        Console.WriteLine("Property Names: ");
        foreach (PropertyData property in properties)
        {
            Console.WriteLine(property.Name);
        }
        Console.WriteLine();

        // Get the Qualifiers in the class
        QualifierDataCollection qualifiers =
            c.Qualifiers;

        // display the qualifiers
        Console.WriteLine("Qualifier Names: ");
        foreach (QualifierData qualifier in qualifiers)
        {
            Console.WriteLine(qualifier.Name);
        }
    }
}
Imports System.Management


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

        ' Get the WMI class
        Dim c As New ManagementClass("Win32_LogicalDisk")

        ' Get the methods in the class
        Dim methods As MethodDataCollection
        methods = c.Methods

        ' display the methods
        Console.WriteLine("Method Names: ")
        For Each method As MethodData In methods

            Console.WriteLine(method.Name)
        Next
        Console.WriteLine()

        ' Get the properties in the class
        Dim properties As PropertyDataCollection
        properties = c.Properties

        ' display the properties
        Console.WriteLine("Property Names: ")
        For Each p As PropertyData In properties

            Console.WriteLine(p.Name)
        Next
        Console.WriteLine()

        ' Get the Qualifiers in the class
        Dim qualifiers As QualifierDataCollection = _
        c.Qualifiers()

        ' display the qualifiers
        Console.WriteLine("Qualifier Names: ")
        For Each qualifier As QualifierData In qualifiers

            Console.WriteLine(qualifier.Name)
        Next

    End Function
End Class

注解

.NET Framework 安全性

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

适用于

ManagementClass(ManagementPath, ObjectGetOptions)

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

使用指定选项初始化 ManagementClass 类的一个新实例,将其初始化到给定的 WMI 类路径。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

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

参数

path
ManagementPath

表示 WMI 类路径的 ManagementPath 实例。 该类表示 WMI 中的一个 CIM 管理类。 CIM 类表示包括硬件、软件、进程等在内的管理信息。 有关 Windows 中可用的 CIM 类的详细信息,请参阅 CIM 类

options
ObjectGetOptions

一个 ObjectGetOptions,它表示检索此类时要使用的选项。

示例

以下示例演示如何使用ManagementClass构造函数初始化ManagementClass变量。 该示例列出了方法、属性和限定符, (包括已创建的类) 修改的限定符。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class
        ManagementPath p =
            new ManagementPath("Win32_Process");
        // Options specify that amended qualifiers
        // are to be retrieved along with the class
        ObjectGetOptions o = new ObjectGetOptions(
            null, System.TimeSpan.MaxValue, true);
        ManagementClass c = new ManagementClass(p,o);

        // Get the methods in the class
        MethodDataCollection methods =
            c.Methods;

        // display the methods
        Console.WriteLine("Method Names: ");
        foreach (MethodData method in methods)
        {
            Console.WriteLine(method.Name);
        }
        Console.WriteLine();

        // Get the properties in the class
        PropertyDataCollection properties =
            c.Properties;

        // display the properties
        Console.WriteLine("Property Names: ");
        foreach (PropertyData property in properties)
        {
            Console.WriteLine(property.Name);
        }
        Console.WriteLine();

        // Get the Qualifiers in the class
        QualifierDataCollection qualifiers =
            c.Qualifiers;

        // display the qualifiers
        Console.WriteLine("Qualifier Names: ");
        foreach (QualifierData qualifier in qualifiers)
        {
            Console.WriteLine(qualifier.Name);
        }
    }
}
Imports System.Management


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

        ' Get the WMI class
        Dim p As New ManagementPath("Win32_Process")
        ' Options specify that amended qualifiers
        ' are to be retrieved along with the class
        Dim o As New ObjectGetOptions( _
            Nothing, System.TimeSpan.MaxValue, True)
        Dim c As New ManagementClass(p, o)

        ' Get the methods in the class
        Dim methods As MethodDataCollection
        methods = c.Methods

        ' display the methods
        Console.WriteLine("Method Names: ")
        For Each method As MethodData In methods

            Console.WriteLine(method.Name)
        Next
        Console.WriteLine()

        ' Get the properties in the class
        Dim properties As PropertyDataCollection
        properties = c.Properties

        ' display the properties
        Console.WriteLine("Property Names: ")
        For Each pdata As PropertyData In properties

            Console.WriteLine(pdata.Name)
        Next
        Console.WriteLine()

        ' Get the Qualifiers in the class
        Dim qualifiers As QualifierDataCollection = _
        c.Qualifiers()

        ' display the qualifiers
        Console.WriteLine("Qualifier Names: ")
        For Each qualifier As QualifierData In qualifiers

            Console.WriteLine(qualifier.Name)
        Next

    End Function
End Class

注解

.NET Framework 安全性

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

适用于

ManagementClass(SerializationInfo, StreamingContext)

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

注意

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

ManagementClassSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。

protected:
 ManagementClass(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected ManagementClass (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 ManagementClass (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Management.ManagementClass : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementClass
[<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.ManagementClass : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementClass
Protected Sub New (info As SerializationInfo, context As StreamingContext)

参数

info
SerializationInfo

SerializationInfo 类的实例,它包含序列化新的 ManagementClass 实例所需的信息。

context
StreamingContext

StreamingContext 类的实例,它包含与新的 ManagementClass 关联的序列化流的源。

属性

注解

.NET Framework 安全性

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

适用于

ManagementClass(String, ObjectGetOptions)

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

使用指定选项初始化 ManagementClass 类的一个新实例,将其初始化到给定的 WMI 类路径。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

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

参数

path
String

WMI 类的路径。 该类表示 WMI 中的一个 CIM 管理类。 CIM 类表示包括硬件、软件、进程等在内的管理信息。 有关 Windows 中可用的 CIM 类的详细信息,请参阅 CIM 类

options
ObjectGetOptions

一个 ObjectGetOptions,它表示检索 WMI 类时要使用的选项。

示例

以下示例演示如何使用ManagementClass构造函数初始化ManagementClass变量。 该示例列出了方法、属性和限定符, (包括已创建的类) 修改的限定符。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class
        //Options specify that amended qualifiers
        // should be retrieved along with the class
        ObjectGetOptions o = new ObjectGetOptions(
            null, System.TimeSpan.MaxValue, true);
        ManagementClass c =
            new ManagementClass("Win32_ComputerSystem",o);

        // Get the methods in the class
        MethodDataCollection methods =
            c.Methods;

        // display the methods
        Console.WriteLine("Method Names: ");
        foreach (MethodData method in methods)
        {
            Console.WriteLine(method.Name);
        }
        Console.WriteLine();

        // Get the properties in the class
        PropertyDataCollection properties =
            c.Properties;

        // display the properties
        Console.WriteLine("Property Names: ");
        foreach (PropertyData property in properties)
        {
            Console.WriteLine(property.Name);
        }
        Console.WriteLine();

        // Get the Qualifiers in the class
        QualifierDataCollection qualifiers =
            c.Qualifiers;

        // display the qualifiers
        Console.WriteLine("Qualifier Names: ");
        foreach (QualifierData qualifier in qualifiers)
        {
            Console.WriteLine(qualifier.Name);
        }
    }
}
Imports System.Management

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

        ' Get the WMI class
        ' Options specify that amended qualifiers
        ' should be retrieved along with the class
        Dim o As New ObjectGetOptions( _
            Nothing, System.TimeSpan.MaxValue, True)
        Dim c As New ManagementClass("Win32_ComputerSystem", o)

        ' Get the methods in the class
        Dim methods As MethodDataCollection
        methods = c.Methods

        ' display the methods
        Console.WriteLine("Method Names: ")
        For Each method As MethodData In methods

            Console.WriteLine(method.Name)
        Next
        Console.WriteLine()

        ' Get the properties in the class
        Dim properties As PropertyDataCollection
        properties = c.Properties

        ' display the properties
        Console.WriteLine("Property Names: ")
        For Each p As PropertyData In properties

            Console.WriteLine(p.Name)
        Next
        Console.WriteLine()

        ' Get the Qualifiers in the class
        Dim qualifiers As QualifierDataCollection = _
        c.Qualifiers()

        ' display the qualifiers
        Console.WriteLine("Qualifier Names: ")
        For Each qualifier As QualifierData In qualifiers

            Console.WriteLine(qualifier.Name)
        Next

    End Function
End Class

注解

.NET Framework 安全性

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

适用于

ManagementClass(ManagementScope, ManagementPath, ObjectGetOptions)

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

在指定的范围内,使用指定选项为指定的 WMI 类初始化 ManagementClass 类的一个新实例。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

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

参数

scope
ManagementScope

一个 ManagementScope,它指定 WMI 类驻留的范围(服务器和命名空间)。

path
ManagementPath

一个 ManagementPath,它表示指定范围内的 WMI 类的路径。 该类表示 WMI 中的一个 CIM 管理类。 CIM 类表示包括硬件、软件、进程等在内的管理信息。 有关 Windows 中可用的 CIM 类的详细信息,请参阅 CIM 类

options
ObjectGetOptions

一个 ObjectGetOptions,它指定检索 WMI 类时要使用的选项。

示例

以下示例演示如何使用ManagementClass构造函数初始化ManagementClass变量。 该示例列出了方法、属性和限定符, (包括已创建的类) 修改的限定符。 必须更改代码中的范围 (命名空间) ,该示例才能在计算机上正确运行。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class
        ManagementScope s =
            new ManagementScope("\\\\MyBox\\root\\cimv2");
        ManagementPath p = new ManagementPath("Win32_Environment");
        ObjectGetOptions o = new ObjectGetOptions(
            null, System.TimeSpan.MaxValue, true);
        ManagementClass c = new ManagementClass(s, p, o);

        // Get the methods in the class
        MethodDataCollection methods =
            c.Methods;

        // display the methods
        Console.WriteLine("Method Names: ");
        foreach (MethodData method in methods)
        {
            Console.WriteLine(method.Name);
        }
        Console.WriteLine();

        // Get the properties in the class
        PropertyDataCollection properties =
            c.Properties;

        // display the properties
        Console.WriteLine("Property Names: ");
        foreach (PropertyData property in properties)
        {
            Console.WriteLine(property.Name);
        }
        Console.WriteLine();

        // Get the Qualifiers in the class
        QualifierDataCollection qualifiers =
            c.Qualifiers;

        // display the qualifiers
        Console.WriteLine("Qualifier Names: ");
        foreach (QualifierData qualifier in qualifiers)
        {
            Console.WriteLine(qualifier.Name);
        }
    }
}
Imports System.Management

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

        ' Get the WMI class
        Dim s As New ManagementScope("\\MyBox\root\cimv2")
        Dim p As New ManagementPath("Win32_Environment")
        Dim o As New ObjectGetOptions( _
            Nothing, System.TimeSpan.MaxValue, True)
        Dim c As New ManagementClass(s, p, o)

        ' Get the methods in the class
        Dim methods As MethodDataCollection
        methods = c.Methods

        ' display the methods
        Console.WriteLine("Method Names: ")
        For Each method As MethodData In methods

            Console.WriteLine(method.Name)
        Next
        Console.WriteLine()

        ' Get the properties in the class
        Dim properties As PropertyDataCollection
        properties = c.Properties

        ' display the properties
        Console.WriteLine("Property Names: ")
        Dim data As PropertyData
        For Each data In properties

            Console.WriteLine(data.Name)
        Next
        Console.WriteLine()

        ' Get the Qualifiers in the class
        Dim qualifiers As QualifierDataCollection = _
        c.Qualifiers()

        ' display the qualifiers
        Console.WriteLine("Qualifier Names: ")
        For Each qualifier As QualifierData In qualifiers

            Console.WriteLine(qualifier.Name)
        Next

    End Function
End Class

注解

可以将路径指定为完整路径 (包括服务器和命名空间) 。 但是,如果指定了范围,它将替代完整路径的第一部分。

.NET Framework 安全性

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

适用于

ManagementClass(String, String, ObjectGetOptions)

Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs
Source:
ManagementClass.cs

在指定的范围内,使用指定选项为指定的 WMI 类初始化 ManagementClass 类的新实例。 该类表示 WMI 中的一个公共信息模型 (CIM) 管理类,如“Win32_LogicalDisk”和“Win32_Process”,前者表示磁盘驱动器,后者表示进程(如 Notepad.exe)

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

参数

scope
String

WMI 类在其中驻留的范围。

path
String

指定范围内的 WMI 类的路径。 该类表示 WMI 中的一个 CIM 管理类。 CIM 类表示包括硬件、软件、进程等在内的管理信息。 有关 Windows 中可用的 CIM 类的详细信息,请参阅 CIM 类

options
ObjectGetOptions

一个 ObjectGetOptions,它指定检索 WMI 类时要使用的选项。

示例

以下示例演示如何使用ManagementClass构造函数初始化ManagementClass变量。 该示例列出了方法、属性和限定符, (包括已创建的类) 修改的限定符。 必须更改代码中的范围 (命名空间) ,该示例才能在计算机上正确运行。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class
        //Options specify that amended qualifiers
        // should be retrieved along with the class
        ManagementClass c =
            new ManagementClass("\\\\MyBox\\root\\cimv2",
            "Win32_Environment",
            new ObjectGetOptions(
            null, System.TimeSpan.MaxValue, true));

        // Get the methods in the class
        MethodDataCollection methods =
            c.Methods;

        // display the methods
        Console.WriteLine("Method Names: ");
        foreach (MethodData method in methods)
        {
            Console.WriteLine(method.Name);
        }
        Console.WriteLine();

        // Get the properties in the class
        PropertyDataCollection properties =
            c.Properties;

        // display the properties
        Console.WriteLine("Property Names: ");
        foreach (PropertyData property in properties)
        {
            Console.WriteLine(property.Name);
        }
        Console.WriteLine();

        // Get the Qualifiers in the class
        QualifierDataCollection qualifiers =
            c.Qualifiers;

        // display the qualifiers
        Console.WriteLine("Qualifier Names: ");
        foreach (QualifierData qualifier in qualifiers)
        {
            Console.WriteLine(qualifier.Name);
        }
    }
}
Imports System.Management


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

        ' Get the WMI class
        ' Options specify that amended qualifiers
        ' should be retrieved along with the class
        Dim c As New ManagementClass("\\MyBox\root\cimv2", _
            "Win32_Environment", _
            New ObjectGetOptions( _
            Nothing, System.TimeSpan.MaxValue, True))


        ' Get the methods in the class
        Dim methods As MethodDataCollection
        methods = c.Methods

        ' display the methods
        Console.WriteLine("Method Names: ")
        For Each method As MethodData In methods

            Console.WriteLine(method.Name)
        Next
        Console.WriteLine()

        ' Get the properties in the class
        Dim properties As PropertyDataCollection
        properties = c.Properties

        ' display the properties
        Console.WriteLine("Property Names: ")
        For Each p As PropertyData In properties

            Console.WriteLine(p.Name)
        Next
        Console.WriteLine()

        ' Get the Qualifiers in the class
        Dim qualifiers As QualifierDataCollection = _
        c.Qualifiers()

        ' display the qualifiers
        Console.WriteLine("Qualifier Names: ")
        For Each qualifier As QualifierData In qualifiers

            Console.WriteLine(qualifier.Name)
        Next

    End Function
End Class

注解

可以将路径指定为完整路径 (包括服务器和命名空间) 。 但是,如果指定了范围,它将替代完整路径的第一部分。

.NET Framework 安全性

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

适用于