开发者

Using RegQueryValueEx and HKEY_PERFORMANCE_COUNTER to Get "Disk Bytes/sec%

开发者 https://www.devze.com 2023-02-20 03:44 出处:网络
I\'ve looked for examples and documentation, but I still can\'t figure this out... How do you use RegQueryValueEx (not the PdhXxx functions) to query for something like Disk Bytes/sec?

I've looked for examples and documentation, but I still can't figure this out...

How do you use RegQueryValueEx (not the PdhXxx functions) to query for something like Disk Bytes/sec?

I've tried the following:

DWORD type;
static union { TCHAR Data[32 * 1024]; PERF_DATA_BLOCK Perf; } perf;//Stack buffer
DWORD cbData = sizeof(perf);
LSTATUS s = RegQueryValueEx(HKEY_PERFORMANCE_DATA,
    _T("PhysicalDisk"), NULL, &typ开发者_如何转开发e, (LPBYTE)&perf, &cbData);
PPERF_OBJECT_TYPE pObjType =
    (PPERF_OBJECT_TYPE)((BYTE*)&perf + perf.Perf.HeaderLength);

but it just returns a header with no data. :(


You can't query for the data by name like that. Instead, you need to query by index. MSDN can help you with some code to find out the appropriate index to query. Unfortunately, you need to make the determination of which index at run-time.

For example, the following SHOULD retrieve the performance data for the processor.

LSTATUS s = RegQueryValueEx(HKEY_PERFORMANCE_DATA, _T("238"), NULL,
    &type, (LPBYTE)&perf, &cbData);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号