Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i get current cpu frequency and harddisk name in kernel mode or user mode without use WMI....thanks
Posted
Comments
Sergey Alexandrovich Kryukov 2-Mar-15 21:58pm    
Why without WMI? You don't say you need something special (avoiding polling, high performance)...
—SA
Member 10258940 3-Mar-15 2:22am    
i can get frequency.....but i can't get Temperature of cpu and harddisk.......

1 solution

You can get the cpu freq from the registry, or you can calculate it yourself.
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\~MHZ

You can get info about the harddisk in roughly the same place:
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0


In order to compute the speed yourself, you can use the following code. The value returned is the speed in MHz. Divide by 1000 to get GHz.

C++
unsigned int hiPart, loPart;
unsigned __int64 CycleCount()
{
    __int64 result;
   asm(
    "rdtsc\n"
    "mov %eax, _loPart\n"
    "mov %edx, _hiPart"
   );
   result = hiPart;
   result <<= 32;
   result |= loPart;
   return result;
}
int GetCpuSpeed()
{
   unsigned __int64 start, stop, elapsed;
   unsigned int total;
   start = CycleCount();
   Sleep(1000);
   stop = CycleCount();
   elapsed = stop - start;
   total = (unsigned)(stop/1000000);
   return total;
}


In my case, the registry returns "2494" (Mhz) and the above snippet returns a value of 2,492 (Mhz).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900