#include <iostream>
#include <windows.h>
#include <setupapi.h>
#include <iomanip>
std::wstring GetHKEY(HKEY key);
int main(int argc, char** argv) {
const LPCWSTR msgCaption = L"EDID.cpp";
DWORD dwSize;
GUID* ptrGUID = NULL;
BOOL bResult = SetupDiClassGuidsFromNameW(L"Monitor", NULL, NULL, &dwSize);
if (bResult == FALSE)
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
ptrGUID = new GUID[dwSize];
bResult = SetupDiClassGuidsFromNameW(L"Monitor", ptrGUID, dwSize, &dwSize);
if (!bResult)
{
MessageBoxW(NULL, L"Unable to retrieve GUID of the specified class.", msgCaption, MB_ICONERROR);
return 1;
}
}
else
{
MessageBoxW(NULL, L"Unable to retrieve GUID of the specified class.", msgCaption, MB_ICONERROR);
return 1;
}
}
HDEVINFO devINFO = INVALID_HANDLE_VALUE;
devINFO = SetupDiGetClassDevsW(ptrGUID, NULL, NULL, DIGCF_PRESENT);
if (devINFO == INVALID_HANDLE_VALUE)
{
MessageBoxW(NULL, L"Failed to retrieve device information of the GUID class.", msgCaption, MB_ICONERROR);
return 1;
}
SP_DEVINFO_DATA devDATA;
devDATA.cbSize = sizeof(SP_DEVINFO_DATA);
BOOL devFOUND = TRUE;
for (DWORD index = 0; devFOUND; index++)
{
devFOUND = SetupDiEnumDeviceInfo(devINFO, index, &devDATA);
if (devFOUND)
{
if (index != 0)
std::wcout << std::endl;
HKEY devKEY = SetupDiOpenDevRegKey(devINFO, &devDATA, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
std::wprintf(L"Registry Key: \"%s\"\n", GetHKEY(devKEY).c_str());
BYTE byteBUFFER[256] = { 0 };
DWORD regSize = sizeof(byteBUFFER);
DWORD regType = REG_BINARY;
LONG lResult = RegQueryValueExW(devKEY, L"EDID", NULL, ®Type, byteBUFFER, ®Size);
if (lResult != ERROR_SUCCESS) {
std::wcout << "!ERROR: " << lResult << std::endl;
}
else
{
for (short i = 0; i < sizeof(byteBUFFER); i++)
std::wcout << std::hex << std::setfill(L'0') << std::setw(2) << int(byteBUFFER[i]) << L" ";
std::wcout << std::endl;
}
}
}
delete[] ptrGUID;
ptrGUID = nullptr;
std::cin.get();
return 0;
}
std::wstring GetHKEY(HKEY key)
{
std::wstring keyPath;
if (key != NULL)
{
HMODULE dll = LoadLibraryW(L"ntdll.dll");
if (dll != NULL) {
typedef NTSTATUS(__stdcall* NtQueryKeyType)(
HANDLE KeyHandle,
int KeyInformationClass,
PVOID KeyInformation,
ULONG Length,
PULONG ResultLength);
NtQueryKeyType func = reinterpret_cast<NtQueryKeyType>(::GetProcAddress(dll, "NtQueryKey"));
if (func != NULL) {
DWORD size = 0;
DWORD result = 0;
result = func(key, 3, 0, 0, &size);
if (result == ((NTSTATUS)0xC0000023L))
{
size = size + 2;
wchar_t* buffer = new (std::nothrow) wchar_t[size / sizeof(wchar_t)];
if (buffer != NULL)
{
result = func(key, 3, buffer, size, &size);
if (result == ((NTSTATUS)0x00000000L))
{
buffer[size / sizeof(wchar_t)] = L'\0';
keyPath = std::wstring(buffer + 2);
}
delete[] buffer;
}
}
}
FreeLibrary(dll);
}
}
return keyPath;
}
可以直接运行,运行之后会获得
这样的一堆16进制数,然后可以放入网站进行解析。推荐一个解析地址: