当前位置:网站首页>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;
}

边栏推荐
猜你喜欢
![[Mini Program Column] Summarize the development specifications of uniapp to develop small programs](/img/7b/110d324eba00652e4987bc623a5bc6.png)
[Mini Program Column] Summarize the development specifications of uniapp to develop small programs

SQL row-column conversion

Concise Notes on Integrals - Types of Curve Integrals of the Second Kind

如何使用 Jmeter 进行抢购、秒杀等场景下,进行高并发?

嘉为鲸翼·多云管理平台荣获信通院可信云技术服务最佳实践

基于JSP实现校园二手交易平台

How to implement Golang DES encryption and decryption?

hcip 第14天学习笔记

The blockbuster IP that has been popular in the world for 25 years, the new work has become a script paradise

【无标题】
随机推荐
Dynamic Lead Time Promising
test4
cmd命令
It is said that FPGA is high-end, what can it do?
How to implement Golang DES encryption and decryption?
[Yugong Series] July 2022 Go Teaching Course 021-Slicing Operation of Go Containers
PCB板加工流程中哪些因素会影响到传输线阻抗
hcip实验
信号完整性测试
Flutter 环境变量配置和flutter doctor中的错误解决
typescript5 - compile and install ts code
js currying
剖析SGI STL空间配置器(_S_refill内存块填充函数)
编程界的“躲猫猫”比赛 | 每日趣闻
电脑文档误删除怎么恢复,恢复误删除电脑文档的方法
R安装包出现error in rawtochar(block[seq_len(ns)]) :
HashSet and LinkedHashSet
opencv可以有多有趣
DDR、GDDR、QDR的区别
经典毕业设计:基于SSM实现高校后勤报修系统