次の方法で共有


ManagementClass コンストラクタ (ManagementScope, ManagementPath, ObjectGetOptions)

指定したオプションを使用して、指定したスコープ内の指定した WMI クラスに対する、ManagementClass クラスの新しいインスタンスを初期化します。このクラスは、ディスク ドライブを表す Win32_LogicalDisk、Notepad.exe などのプロセスを表す Win32_Process など、WMI の CIM (Common Information Model) 管理クラスを表します。詳細については、MSDN ライブラリ (https://msdn.microsoft.com/library/ja) の Windows Management Instrumentation に関するドキュメントで Win32 クラスのトピックを参照してください。

名前空間: System.Management
アセンブリ: System.Management (system.management.dll 内)

構文

'宣言
Public Sub New ( _
    scope As ManagementScope, _
    path As ManagementPath, _
    options As ObjectGetOptions _
)
'使用
Dim scope As ManagementScope
Dim path As ManagementPath
Dim options As ObjectGetOptions

Dim instance As New ManagementClass(scope, path, options)
public ManagementClass (
    ManagementScope scope,
    ManagementPath path,
    ObjectGetOptions options
)
public:
ManagementClass (
    ManagementScope^ scope, 
    ManagementPath^ path, 
    ObjectGetOptions^ options
)
public ManagementClass (
    ManagementScope scope, 
    ManagementPath path, 
    ObjectGetOptions options
)
public function ManagementClass (
    scope : ManagementScope, 
    path : ManagementPath, 
    options : ObjectGetOptions
)

パラメータ

  • scope
    WMI クラスが存在するスコープ (サーバーと名前空間) を指定する ManagementScope
  • path
    指定したスコープの WMI クラスへのパスを表す ManagementPath。クラスは、WMI の CIM 管理クラスを表します。CIM クラスは、ハードウェア、ソフトウェア、プロセスなどの管理情報を表します。Windows で使用できる CIM クラスの詳細については、MSDN ライブラリ (https://msdn.microsoft.com/library/ja) の Windows Management Instrumentation に関するドキュメントで Win32 クラスのトピックを参照してください。
  • options
    WMI クラスの取得時に使用するオプションを指定する ObjectGetOptions

解説

パスは、(サーバーと名前空間を含む) 完全パスとして指定できます。ただし、スコープを指定する場合、完全パスの最初の部分はオーバーライドされます。

.NET Framework のセキュリティ

直前の呼び出し元に対する完全な信頼。このメンバは、信頼性が一部しか確認されていないコードでは使用できません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

使用例

ManagementClass コンストラクタを使用して、ManagementClass 変数を初期化する方法の例を次に示します。この例では、作成されたクラスのメソッド、プロパティ、および修飾子 (修正済みの修飾子を含む) を一覧表示します。コンピュータでコードを正しく実行するには、例のコードのスコープ (名前空間) を変更する必要があります。

Imports System
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
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);
        }

    }
}

.NET Framework のセキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「」を参照してください。

プラットフォーム

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

ManagementClass クラス
ManagementClass メンバ
System.Management 名前空間