Using the Registry Functions to Consume Counter Data
Use the registry functions to collect performance data from the special
HKEY_PERFORMANCE_DATA registry key.
Performance data is not actually stored in the registry. Calling the registry functions causes the system to collect the data from the appropriate performance data provider.
You should not normally use the registry functions to consume counter data. Instead, you should use the Performance Data Helper (PDH) functions. The PDH functions are easier to use and avoid many performance and reliability problems that can occur through incorrect use of the registry functions.
You cannot use the registry functions if you are writing Windows OneCore apps. Instead, use PerfLib V2 Consumer functions.
The registry functions are the low-level API for collecting data from V1 providers. The registry functions also support collecting data from V2 providers via a translation layer that calls into the V2 Consumer functions.
To obtain performance data from the local system, call the RegQueryValueEx function. Use
HKEY_PERFORMANCE_DATA as the key. The first call opens the key. You do not need to explicitly open the key first.
To obtain performance data from a remote system, call the RegConnectRegistry function. Use the computer name of the remote system and use
HKEY_PERFORMANCE_DATA as the key. This call retrieves a key representing the performance data for the remote system. Use this key rather than
HKEY_PERFORMANCE_DATA key to retrieve the data.
Be sure to use the RegCloseKey function to close the handle to the key when you are finished obtaining the performance data. This is important for both the local and remote cases:
RegCloseKey(HKEY_PERFORMANCE_DATA)does not actually close a registry handle, but it clears all cached data and frees the loaded performance DLLs.
RegCloseKey(hkeyRemotePerformanceData)closes the handle to the remote machine's registry.
Do not call
You use the
lpValueName parameter of the RegQueryValueEx function to indicate the information to retrieve. The following table lists the values you can specify for
lpValueName. Note that the value strings are not case-sensitive.
||Retrieves performance data for all performance objects registered on the computer except for those included in the
||Windows Vista and later: Retrieves performance data for all V1 performance objects registered on the computer except for those included in the
||Retrieves performance data for one or more performance objects. Specify the decimal index associated with each object that you want to retrieve in a space-separated list. For example, if you want to retrieve System and Memory objects and you have determined that the indexes of the corresponding name strings are 2 and 4, specify the string
||Retrieves name strings for the specified language identifier, e.g. English for
||Retrieves help strings for the specified language identifier, e.g. English for
||Deprecated: Retrieves performance data for object types whose data is expensive to collect in terms of processor time or memory usage. This collection may take several minutes on a heavily-loaded machine. You should perform the collection on a worker thread if your application needs to respond to the user during this data collection.|
For details on the format of the performance data that the registry returns, see Performance Data Format.
For an example that gets the names and descriptions of the registered counters on the computer, see Retrieving Counter Names and Help Text.
For an example that accesses the components of the performance data, see Displaying Object, Instance, and Counter Names.