Skip to content

Instantly share code, notes, and snippets.

@FelixK15
Last active August 22, 2024 09:27
Show Gist options
  • Save FelixK15/63b3666233a30db439629cb9be240d9d to your computer and use it in GitHub Desktop.
Save FelixK15/63b3666233a30db439629cb9be240d9d to your computer and use it in GitHub Desktop.
Read microcode version using win32 registry
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdint.h>
#pragma comment(lib, "Advapi32.lib")
bool tryToFindMicrocodeVersionInRegistry(uint32_t* pOutMicrocodeVersion)
{
bool success = false;
HKEY pProcessorRegistryKey = nullptr;
DWORD bufferLength = MAX_PATH;
const char* pEntryName = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
if(ERROR_SUCCESS != RegOpenKeyA(HKEY_LOCAL_MACHINE, pEntryName, &pProcessorRegistryKey))
{
goto cleanup_and_exit;
}
uint64_t updateRevision = 0u;
DWORD entryLengthInBytes = sizeof(updateRevision);
if(ERROR_SUCCESS != RegGetValueA(pProcessorRegistryKey, nullptr, "Update Revision", RRF_RT_REG_BINARY, nullptr, (PVOID)&updateRevision, &entryLengthInBytes))
{
goto cleanup_and_exit;
}
*pOutMicrocodeVersion = (updateRevision >> 32u);
success = true;
cleanup_and_exit:
if(pProcessorRegistryKey != nullptr)
{
RegCloseKey(pProcessorRegistryKey);
}
return success;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment