Windows-API-examples/system/cpu_speed.c

39 lines
800 B
C
Raw Normal View History

2016-01-31 12:58:16 +00:00
#include <windows.h>
#include <wchar.h>
int wmain(void) {
DWORD BufSize = MAX_PATH;
DWORD mhz = MAX_PATH;
HKEY key;
long r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
2016-02-01 11:14:00 +00:00
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key);
2016-01-31 12:58:16 +00:00
if (r != ERROR_SUCCESS) {
2016-02-01 11:14:00 +00:00
2016-01-31 12:58:16 +00:00
wprintf(L"RegOpenKeyExW() failed %ld", GetLastError());
2016-02-01 11:14:00 +00:00
return 1;
2016-01-31 12:58:16 +00:00
}
r = RegQueryValueExW(key, L"~MHz", NULL, NULL, (LPBYTE) &mhz, &BufSize);
if (r != ERROR_SUCCESS) {
2016-02-01 11:14:00 +00:00
2016-01-31 12:58:16 +00:00
wprintf(L"RegQueryValueExW() failed %ld", GetLastError());
return 1;
}
wprintf(L"CPU speed: %lu MHz\n", mhz);
2016-02-01 11:14:00 +00:00
r = RegCloseKey(key);
if (r != ERROR_SUCCESS) {
wprintf(L"Failed to close registry handle %ld", GetLastError());
return 1;
}
2016-01-31 12:58:16 +00:00
return 0;
}