Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,195 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hello im trying to read the cpu freq from the registry am i doing correct ?
__int64 getCPUFrequencyFromRegistryA()
{
NTSTATUS status;
OBJECT_ATTRIBUTES objAttributes;
UNICODE_STRING keyPath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
HANDLE hKey;
InitializeObjectAttributes(&objAttributes, &keyPath, OBJ_CASE_INSENSITIVE, NULL, NULL);
status = ZwOpenKey(&hKey, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &objAttributes);
if (NT_SUCCESS(status))
{
UNICODE_STRING valueName = RTL_CONSTANT_STRING(L"~MHz");
// Allocate a larger buffer for the KEY_VALUE_PARTIAL_INFORMATION structure
UCHAR buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(DWORD)];
PKEY_VALUE_PARTIAL_INFORMATION kvpi = (PKEY_VALUE_PARTIAL_INFORMATION)buffer;
ULONG resultLength;
status = ZwQueryValueKey(hKey, &valueName, KeyValuePartialInformation, kvpi, sizeof(buffer), &resultLength);
if (NT_SUCCESS(status))
{
DWORD frequency = *(PDWORD)(kvpi->Data);
// Check the status of ZwClose(hKey) and handle potential errors
status = ZwClose(hKey);
if (!NT_SUCCESS(status)) {
// Handle error
}
return (__int64)frequency * 1000000; // Multiply by 1,000,000 to get the frequency in Hz.
}
}
status = ZwClose(hKey);
if (!NT_SUCCESS(status)) {
// Handle error
}
return 0;
}
You can find similar code on GitHub, like :