PdhGetCounterInfo returns a NULL explain text for Version 2 Performance Counters

Applies to: Windows 10Windows 8.1Windows 7 More

Symptoms


Version 2 performance counters were introduced in Windows Vista because the performance counters architecture was changed to simplify the process for providing counter data to consumers. Applications will use either Version 1 or Version 2 performance counter providers. 

Consider a scenario where the PdhGetCounterInfo API is used to retrieve the information about Version 2 performance counters. First you call PdhAddCounter to add a Version 2 performance counter. Then, you call the PdhGetCounterInfo function to get the information. In this scenario, the szExplainText field in the PDH_COUNTER_INFO structure which is returned by PdhGetCounterInfo will be set to NULL. This issue does not apply to Version 1 performance counters.

Cause


This issue occurs because the PdhAddCounter and PdhGetCounterInfo functions don't handle the explain text of Version 2 performance counters properly.

Resolution


This issue has been resolved in Windows 10 version 1703.

Workaround


To work around this issue, retrieve the explain text of Version 2 performance counters directly by using the registry functions. 
 
For example: you can follow these steps:
 
  1. Retrieve text strings for counter names from the HKEY_PERFORMANCE_NLSTEXT registry key:
    RegQueryValueEx(HKEY_PERFORMANCE_NLSTEXT, L"Counter", NULL, NULL, (LPBYTE)pBufferCounter, &dwBufferSize);
  2. Retrieve text strings for the explain text from the HKEY_PERFORMANCE_NLSTEXT registry key:
    RegQueryValueEx(HKEY_PERFORMANCE_NLSTEXT, L"Help", NULL, NULL, (LPBYTE)pBufferHelp, &dwBufferSize);
  3. Retrieve the last index used from the following registry:
    RegOpenKeyEx( HKEY_LOCAL_MACHINE,L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib", 0,KEY_READ, &hkey );RegQueryValueEx(hkey, L"Last Help", NULL, 0, (LPBYTE)&dwEntries,&dwSize);
  4. Use pBufferCounter and pBufferHelp to locate the desired explain text. After locating the index number for the desired counter name from pBufferCounter, increase that index value by one to determine the index of the associated explain text within pBufferHelp. If you need to associate counter names and explain text with counter objects, you can retrieve the object information from the HKEY_PERFORMANCE_DATA registry key: 
    RegQueryValueEx(HKEY_PERFORMANCE_DATA, L"Global", NULL, NULL, pBuffer, &dwSize);
    The GUIDs identifying Version 2 performance counter providers are listed in the registry under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Perflib\_V2Providers". You can find the counter object names as the value named NeutralName for each GUID.

For more information about the registry functions, go to Using the Registry Functions to Consume Counter Data.

Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.