How To Get the Processor Speed

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;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: