How To Get the Processor Speed

December 19, 2008

The processor speed in MHz can be read directly from the registry location HARDWARE\DESCRIPTION\System\CentralProcessor. The following sample code illustrates this.

DWORD GetProcessorSpeed()
{
   HKEY hKey;
   // Read the speed from registry
   const long error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                      "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
                      0,
                      KEY_READ,
                      &hKey);

   DWORD dwMHz = 0;
   DWORD BufSize = MAX_PATH;
   if (ERROR_SUCCESS == error)
   {
      RegQueryValueEx(hKey, "~MHz", 0, 0, (LPBYTE)&dwMHz, &BufSize);
   }
   return dwMHz;
}