当前位置:网站首页>Access to display the data
Access to display the data
2022-07-30 09:21:00 【ThatAllOver】
#define _CRT_NON_CONFORMING_SWPRINTFS
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <tchar.h>
#include <initguid.h>
#include <wmistr.h>
DEFINE_GUID(wmi_monitor_id_guid, 0x671a8285, 0x4edb, 0x4cae, 0x99, 0xfe, 0x69, 0xa1, 0x5c, 0x48, 0xc0, 0xbc);
typedef struct _wmi_monitor_id
{
unsigned short product_code_id[16];
unsigned short serial_number_id[16];
unsigned short manufacturer_name[16];
unsigned char week_of_manufacture;
unsigned short year_of_manufacture;
unsigned short user_friendly_name_length;
unsigned short user_friendly_name[1];
} wmi_monitor_id;
#define OFFSET_TO_PTR(base_address, offset_length) ((PBYTE)((PBYTE)base_address + offset_length))
typedef HRESULT(WINAPI* FWmiOpenBlock) (IN LPGUID , IN DWORD , OUT PLONG);
typedef HRESULT(WINAPI* FWmiQueryAllDataW) (IN LONG , PULONG , OUT PUCHAR);
typedef HRESULT(WINAPI* FWmiCloseBlock) (IN LONG);
int main(int argc, char* argv[])
{
HMODULE advapi32 = LoadLibraryW(L"Advapi32.dll");
if (!advapi32) return 0;
wprintf(L"current process id = %d \r\n", GetCurrentProcessId());
FWmiOpenBlock WmiOpenBlock = (FWmiOpenBlock)GetProcAddress(advapi32, "WmiOpenBlock");
FWmiQueryAllDataW WmiQueryAllData = (FWmiQueryAllDataW)GetProcAddress(advapi32, "WmiQueryAllDataW");
FWmiCloseBlock WmiCloseBlock = (FWmiCloseBlock)GetProcAddress(advapi32, "WmiCloseBlock");
if (WmiOpenBlock && WmiQueryAllData && WmiCloseBlock)
{
LONG handle = 0;
HRESULT hr = WmiOpenBlock((LPGUID)&wmi_monitor_id_guid, GENERIC_READ, &handle);
if (hr == S_OK)
{
ULONG buffer_size = 1024 * 4;
UCHAR* data_buffer = new UCHAR[buffer_size];
if (data_buffer)
{
memset(data_buffer, 0, buffer_size);
hr = WmiQueryAllData(handle, &buffer_size, data_buffer);
if (hr == S_OK)
{
while (true)
{
wmi_monitor_id* monitor_id = nullptr;
PWNODE_ALL_DATA all_data = (PWNODE_ALL_DATA)data_buffer;
if (all_data->WnodeHeader.Flags & WNODE_FLAG_FIXED_INSTANCE_SIZE)
monitor_id = (wmi_monitor_id*)&data_buffer[all_data->DataBlockOffset];
else
monitor_id = (wmi_monitor_id*)&data_buffer[all_data->OffsetInstanceDataAndLength[0].OffsetInstanceData];
ULONG offset = (ULONG)data_buffer[all_data->OffsetInstanceNameOffsets];
WCHAR* instance_name = (WCHAR*)OFFSET_TO_PTR(all_data, offset + sizeof(USHORT));
wprintf(L"instance name = %s \r\n", instance_name);
WCHAR* user_friendly_name = (WCHAR*)monitor_id->user_friendly_name;
wprintf(L"user friendly name = %s \r\n", user_friendly_name);
WCHAR* manufacturer_name = (WCHAR*)monitor_id->manufacturer_name;
wprintf(L"manufacturer name = %s \r\n", manufacturer_name);
WCHAR* product_code_id = (WCHAR*)monitor_id->product_code_id;
wprintf(L"product code id = %s \r\n", product_code_id);
WCHAR* serial_number_id = (WCHAR*)monitor_id->serial_number_id;
wprintf(L"serial number id = %s \r\n", serial_number_id);
if (!all_data->WnodeHeader.Linkage) break;
data_buffer += all_data->WnodeHeader.Linkage;
}
}
delete[] data_buffer;
}
WmiCloseBlock(handle);
}
}
system("pause");
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-上
一文读懂二十种开关电源拓扑结构
反射技巧让你的性能提升 N 倍
TreeSet parsing
剖析SGI STL空间配置器(allocate内存分配函数)
How to use Jmeter to carry out high concurrency in scenarios such as panic buying and seckill?
Integral Special Notes-Three Formulas for Curve Area Integral
The R installation package has error in rawtochar(block[seq_len(ns)]) :
Farthest Point Sampling - D-FPS vs F-FPS
SQL row-column conversion
leetcode-990:等式方程的可满足性
与tcp协议有关的几个知识点
HCIP --- MPLS VPN实验
Taosi TDengine 2.6+ optimization parameters
积分简明笔记-第二类曲线积分的类型
The full arrangement of the 46th question in C language.Backtracking
Network/Information Security Top Journal and Related Journals Conference
回板后,处理器不启动,怎么办?
经典毕业设计:基于SSM实现高校后勤报修系统
详解JVM垃圾回收