Platform SDK: Performance Monitoring

PdhLookupPerfIndexByName

The PdhLookupPerfIndexByName function returns the counter index corresponding to the specified counter name.

PDH_FUNCTION PdhLookupPerfIndexByName(
  LPCTSTR *szMachineName,   
  LPCTSTR szNameBuffer,     
  LPDWORD pdwIndex          
);

Parameters

szMachineName
[in] A pointer to a null-terminated string containing the name of a buffer that contains the name of the machine where the specified counter is located. The machine name can be specified by the DNS name or the IP address.
szNameBuffer
[in] A pointer to a null-terminated string containing the name of a buffer that contains the full name of the counter.
pdwIndex
[out] A pointer to a DWORD that receives the index of the counter.

Return Values

If the function succeeds, it returns ERROR_SUCCESS.

If the function fails, the return value is a PDH error status defined in PDHMsg.h. The following are possible error values.

Error value Description
PDH_INVALID_ARGUMENT An argument is not correct or is incorrectly formatted.

Remarks

The general counter path format is as follows:

\\machine\object(parent/instance#index)\counter

The parent, instance, index, and counter components of the format may contain either a valid name or a wildcard character. The machine, parent, instance, and index components are not necessary for all counters.

The counter paths you must use is determined by the counter itself. For example, the LogicalDisk object has an instance index, so you must provide the #index, or a wildcard. Therefore, you could use the following format:

\LogicalDisk(*/*#*)\*

In comparison, the Process object does not require an instance index. Therefore, you could use the following format:

\Process(*)\ID Process

The following is a list of the possible formats:

Requirements

  Windows NT/2000: Requires Windows 2000.
  Header: Declared in Pdh.h.
  Library: Use Pdh.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows 2000.

See Also

PdhLookupPerfNameByIndex