.NET Framework Class Library
ManagementPath Class
Provides a wrapper for parsing and building paths to WMI objects.
Inheritance Hierarchy
System.Object
System.Management.ManagementPath
Namespace: System.Management
Assembly: System.Management (in System.Management.dll)
Syntax
Visual Basic
Public Class ManagementPath _ Implements ICloneable
C#
public class ManagementPath : ICloneable
Visual C++
public ref class ManagementPath : ICloneable
F#
type ManagementPath = class interface ICloneable end
The ManagementPath type exposes the following members.
Constructors
| Name | Description | |
|---|---|---|
|
ManagementPath() | Initializes a new instance of the ManagementPath class that is empty. This is the default constructor. |
|
ManagementPath(String) | Initializes a new instance of the ManagementPath class for the given path. |
Properties
| Name | Description | |
|---|---|---|
|
ClassName | Gets or sets the class portion of the path. |
|
DefaultPath | Gets or sets the default scope path used when no scope is specified. The default scope is \\.\root\cimv2, and can be changed by setting this property. |
|
IsClass | Gets or sets a value indicating whether this is a class path. |
|
IsInstance | Gets or sets a value indicating whether this is an instance path. |
|
IsSingleton | Gets or sets a value indicating whether this is a singleton instance path. |
|
NamespacePath | Gets or sets the namespace part of the path. Note that this does not include the server name, which can be retrieved separately. |
|
Path | Gets or sets the string representation of the full path in the object. |
|
RelativePath | Gets or sets the relative path: class name and keys only. |
|
Server | Gets or sets the server part of the path. |
Methods
| Name | Description | |
|---|---|---|
|
Clone | Returns a copy of the ManagementPath. |
|
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
|
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
|
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
|
GetType | Gets the Type of the current instance. (Inherited from Object.) |
|
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
|
SetAsClass | Sets the path as a new class path. This means that the path must have a class name but not key values. |
|
SetAsSingleton | Sets the path as a new singleton object path. This means that it is a path to an instance but there are no key values. |
|
ToString | Returns the full object path as the string representation. (Overrides Object.ToString().) |
Explicit Interface Implementations
| Name | Description | |
|---|---|---|
|
ICloneable.Clone | Creates a new object that is a copy of the current instance. |
Examples
The following example demonstrates how the ManagementPath class parses a path to a WMI object. The path that is parsed in the example is a path to an instance of a class.
Visual Basic
Imports System 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
C#
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:"" } }
Version Information
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.See Also
Reference
Community Content
Bruno Maestro
Alterando o Nome do Computador - Change Computer Name
Imports System Imports System.Management
Dim myPath AsNewManagementPath
myPath.Server=System.Net.Dns.GetHostName
myPath.NamespacePath="root\CIMV2"
myPath.RelativePath="Win32_Computersystem.Name='"& NOME_COMPUTADOR &"'"Dim myObj AsNewManagementObject(myPath)Dim myParams()AsObject={"NOVO_NOME"}
myObj.InvokeMethod("Rename", myParams)