.Net Runtime Library for Delphi
Close
CNClrLib.Management Namespace

Example 2

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.

Delphi
// This example shows synchronous consumption of events. // The client is blocked while waiting for events. program Sample; {$APPTYPE CONSOLE} {$R *.res} uses SysUtils, CNClrLib.Management, CNClrLib.Core; var Console: _Console; p: _ManagementPath; begin try Console := CoConsole.CreateInstance; // Get the WMI class path p := CoManagementPath.CreateInstance('\\ComputerName\root' + '\cimv2:Win32_LogicalDisk.DeviceID=''C:'''); Console.WriteLine_15('IsClass: {0}', p.IsClass); // Should be False (because it is an instance) Console.WriteLine_15('IsInstance: {0}', p.IsInstance); // Should be True Console.WriteLine_14('ClassName: ' + p.ClassName); // Should be "Win32_LogicalDisk" Console.WriteLine_14('NamespacePath: ' + p.NamespacePath); // Should be "ComputerName\cimv2" Console.WriteLine_14('Server: ' + p.Server); // Should be "ComputerName" Console.WriteLine_14('Path: ' + p.Path); // Should be "ComputerName\root\cimv2: // Win32_LogicalDisk.DeviceId="C:"" Console.WriteLine_14('RelativePath: ' + p.RelativePath); // Should be "Win32_LogicalDisk.DeviceID="C:"" except on E: Exception do begin Console.WriteLine_14(E.message); end; end; end.