ManagementClass 建構函式

定義

初始化 ManagementClass 類別的新執行個體。

多載

ManagementClass()

初始化 ManagementClass 類別的新執行個體。 這是無參數建構函式。

ManagementClass(ManagementPath)

初始化 ManagementClass 類別的新執行個體。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

ManagementClass(String)

初始化 ManagementClass 類別的新執行個體,該類別初始化為指定的路徑。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

ManagementClass(ManagementPath, ObjectGetOptions)

初始化 ManagementClass 類別的新執行個體,這個類別被用指定的選項初始化為 WMI 類別路徑。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

ManagementClass(SerializationInfo, StreamingContext)
已淘汰.

初始化 ManagementClass 類別的新執行個體,這個執行個體是來自 SerializationInfoStreamingContext 類別的指定執行個體。

ManagementClass(String, ObjectGetOptions)

初始化 ManagementClass 類別的新執行個體,這個類別被用指定的選項初始化為 WMI 類別路徑。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

ManagementClass(ManagementScope, ManagementPath, ObjectGetOptions)

在指定的範圍 (Scope),以指定的選項,為指定的 WMI 類別初始化 ManagementClass 類別的新執行個體。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

ManagementClass(String, String, ObjectGetOptions)

在指定的範圍,以指定的選項,為指定的 WMI 類別初始化 ManagementClass 類別的新執行個體。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

備註

.NET Framework 安全性

完全信任立即呼叫者。 這個成員無法供部分信任的程式碼使用。 如需詳細資訊,請參閱 使用部分信任程式代碼的連結庫

ManagementClass()

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
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)

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
ManagementClass.cs

初始化 ManagementClass 類別的新執行個體。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

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)

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
ManagementClass.cs

初始化 ManagementClass 類別的新執行個體,該類別初始化為指定的路徑。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

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)

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
ManagementClass.cs

初始化 ManagementClass 類別的新執行個體,這個類別被用指定的選項初始化為 WMI 類別路徑。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

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)

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
ManagementClass.cs

警告

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

初始化 ManagementClass 類別的新執行個體,這個執行個體是來自 SerializationInfoStreamingContext 類別的指定執行個體。

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)

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
ManagementClass.cs

初始化 ManagementClass 類別的新執行個體,這個類別被用指定的選項初始化為 WMI 類別路徑。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

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)

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
ManagementClass.cs

在指定的範圍 (Scope),以指定的選項,為指定的 WMI 類別初始化 ManagementClass 類別的新執行個體。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

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)

來源:
ManagementClass.cs
來源:
ManagementClass.cs
來源:
ManagementClass.cs

在指定的範圍,以指定的選項,為指定的 WMI 類別初始化 ManagementClass 類別的新執行個體。 此類別表示來自 WMI 的通用訊息模型 (CIM) 管理類別;例如,可以表示磁碟機的 Win32_LogicalDisk,以及可以表示 Notepad.exe 等處理序的 Win32_Process

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 安全性

完全信任立即呼叫者。 這個成員無法供部分信任的程式碼使用。 如需詳細資訊,請參閱 使用部分信任程式代碼的連結庫

適用於