a question of IOCTL_DISK_PERFORMANCE

Hi all,
I wrote a small function to get the diskperformance by calling
IOCTL_DISK_PERFORMANCE. In Windows XP it works perfectly. But in Windows
2000, everything seems ok, (The return value also means it did get
data)but the disk performance structure data is all 0. I am sure I have
turned on the diskperf by “diskperf -y”. And then when I execute
perfmon.exe and add some disk-related counters, my function can now get
performance data well, however when I quit perfmon.exe, it stops
collecting data again.

My function is as below. Could anybody help me to solve this problem?
Thank you so much!!

Chia-mei Tu
mailto:xxxxx@synology.com


int GetPerformance()
{
HANDLE hDisk = NULL;
DWORD cbRet = 0;
int ret = 1;
DISK_PERFORMANCE perfDisk;

hDisk = CreateFile(“\\.\PhysicalDrive0”,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
0, NULL);

if(hDisk == INVALID_HANDLE_VALUE)
{
ret = -1;
goto ERR;
}

ret = DeviceIoControl(hDisk,
IOCTL_DISK_PERFORMANCE,
NULL,
0,
(LPVOID)&perfDisk,
sizeof(DISK_PERFORMANCE),
&cbRet, NULL);

if(ret == 0)
{
ret = GetLastError();
goto ERR;
}

ERR:
CloseHandle(hDisk);
return ret;
}