Skip to content

Instantly share code, notes, and snippets.

@Aetopia
Created July 18, 2025 12:08
Show Gist options
  • Select an option

  • Save Aetopia/81f6b8893c5c03c93fdcd344c9802af6 to your computer and use it in GitHub Desktop.

Select an option

Save Aetopia/81f6b8893c5c03c93fdcd344c9802af6 to your computer and use it in GitHub Desktop.
#include <string>
#include <vector>
#include <format>
#include <initguid.h>
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <devpkey.h>
std::wstring GetCpuName()
{
HDEVINFO info = SetupDiGetClassDevsW(&GUID_DEVCLASS_PROCESSOR, NULL, NULL, DIGCF_PRESENT);
SP_DEVINFO_DATA data = {.cbSize = sizeof(SP_DEVINFO_DATA)};
int index{};
std::vector<byte> string{};
for (; SetupDiEnumDeviceInfo(info, index, &data); index++)
if (string.empty())
{
DWORD size{};
DEVPROPTYPE type{};
SetupDiGetDevicePropertyW(info, &data, &DEVPKEY_Device_FriendlyName, &type, NULL, 0, &size, 0);
string.resize(size);
SetupDiGetDevicePropertyW(info, &data, &DEVPKEY_Device_FriendlyName, &type, string.data(), size, NULL, 0);
}
SetupDiDestroyDeviceInfoList(info);
return std::format(L"{}x {}", index, std::wstring(reinterpret_cast<PWSTR>(string.data())));
}
int main()
{
__builtin_printf("%ls\n", GetCpuName().c_str());
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment