PDHCreateCounter

Function Prototype

PDHCreateCounter(anQueryID : number, asPath : string):number;

Parameters

  • anQueryID (in) - ID of a valid query object created using PDHCreateQuery

  • asPath (in) - Path to the counter required. The path to the counter takes the form

"\<object name>(<instance name>)\<counter name>" or

"\\<machine name>\<object name>(<instance name>)\<counter name>"

For example "\PhysicalDisk(0)\% Disk Time" for a local machine or

"\\roma\PhysicalDisk(0)\% Disk Time" to recover the information from a machine named "roma"

Return Value

number : An ID for the counter requested or -1 if the path is invalid.

Description

Given a query object ID and path to a counter, returns the ID to the requested counter. Data from the counter ID can be retrieved later using PDHCollectData and PDHGetCounterValue.

When using the PdhCreateCounter, remember that performance counters on Windows systems are dynamic in many cases. For example, '\\roma\Process(SerioCC)\Private Bytes' will create a counter that returns the memory usage of the Serio Command Center if the Command Center is running. However, if the process is not running your attempt to create the counter will return an error. In this example, an error condition may indicate simply that the requested performance counter is not available.

Remember you can always use PDHEnumerateObjects and PDHEnumerateObjectItems to enumerate available items.

Example

See example in PDHGetCounterValue