ManagementPath 類別

定義

提供包裝函式剖析和建立通往 WMI 物件的路徑。

public ref class ManagementPath : ICloneable
public class ManagementPath : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Management.ManagementPathConverter))]
public class ManagementPath : ICloneable
type ManagementPath = class
    interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Management.ManagementPathConverter))>]
type ManagementPath = class
    interface ICloneable
Public Class ManagementPath
Implements ICloneable
繼承
ManagementPath
屬性
實作

範例

下列範例示範 類別如何 ManagementPath 剖析 WMI 物件的路徑。 範例中剖析的路徑是類別實例的路徑。

using System;
using System.Management;

public class Sample
{
    public static void Main()
    {

        // Get the WMI class path
        ManagementPath p =
            new ManagementPath(
            "\\\\ComputerName\\root" +
            "\\cimv2:Win32_LogicalDisk.DeviceID=\"C:\"");

        Console.WriteLine("IsClass: " +
            p.IsClass);
        // Should be False (because it is an instance)

        Console.WriteLine("IsInstance: " +
            p.IsInstance);
        // Should be True

        Console.WriteLine("ClassName: " +
            p.ClassName);
        // Should be "Win32_LogicalDisk"

        Console.WriteLine("NamespacePath: " +
            p.NamespacePath);
        // Should be "ComputerName\cimv2"

        Console.WriteLine("Server: " +
            p.Server);
        // Should be "ComputerName"

        Console.WriteLine("Path: " +
            p.Path);
        // Should be "ComputerName\root\cimv2:
        // Win32_LogicalDisk.DeviceId="C:""

        Console.WriteLine("RelativePath: " +
            p.RelativePath);
        // Should be "Win32_LogicalDisk.DeviceID="C:""
    }
}
Imports System.Management


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

        ' Get the WMI class path
        Dim p As ManagementPath = _
            New ManagementPath( _
            "\\ComputerName\root" & _
            "\cimv2:Win32_LogicalDisk.DeviceID=""C:""")

        Console.WriteLine("IsClass: " & _
            p.IsClass)
        ' Should be False (because it is an instance)

        Console.WriteLine("IsInstance: " & _
            p.IsInstance)
        ' Should be True

        Console.WriteLine("ClassName: " & _
            p.ClassName)
        ' Should be "Win32_LogicalDisk"

        Console.WriteLine("NamespacePath: " & _
            p.NamespacePath)
        ' Should be "ComputerName\cimv2"

        Console.WriteLine("Server: " & _
            p.Server)
        ' Should be "ComputerName"

        Console.WriteLine("Path: " & _
            p.Path)
        ' Should be "ComputerName\root\cimv2:
        ' Win32_LogicalDisk.DeviceId="C:""

        Console.WriteLine("RelativePath: " & _
            p.RelativePath)
        ' Should be "Win32_LogicalDisk.DeviceID="C:""

    End Function
End Class

建構函式

ManagementPath()

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

ManagementPath(String)

初始化指定路徑的 ManagementPath 類別新執行個體。

屬性

ClassName

取得或設定路徑的類別部分。

DefaultPath

取得或設定範圍為指定時的所用的預設範圍路徑。 預設範圍是 \\.\root\cimv2,而且設定這個屬性即可變更。

IsClass

取得或設定值,指出這是否為類別路徑。

IsInstance

取得或設定值,指出這是否為執行個體路徑。

IsSingleton

取得或設定值,指出這是否為「單一」執行個體路徑。

NamespacePath

取得或設定路徑的命名空間 (Namespace) 部分。 請注意,這不包含可以個別擷取的伺服器名稱。

Path

取得或設定物件中完整路徑的字串表示。

RelativePath

取得或設定相對路徑:只有類別名稱和索引鍵。

Server

取得或設定路徑的伺服器部分。

方法

Clone()

傳回 ManagementPath 的複本。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
SetAsClass()

將路徑設定為新的類別路徑。 這表示路徑必須具有類別名稱,但是不具有鍵值。

SetAsSingleton()

將路徑設定為新的「單一」物件路徑。 這表示它是通往執行個體的路徑,但是沒有鍵值。

ToString()

將完整的物件路徑傳回為字串表示。

明確介面實作

ICloneable.Clone()

建立目前執行個體複本的新物件。

適用於