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

边栏推荐
猜你喜欢

Detailed explanation of 4D words: C language three-point chess advanced + N-piece chess recursive dynamic judgment of winning or losing
![[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

How to use Jmeter to carry out high concurrency in scenarios such as panic buying and seckill?

ACL 2022 | 引入角度margin构建对比学习目标,增强文本语义判别能力

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

如何避免CMDB沦为数据孤岛?

剖析SGI STL空间配置器(_S_refill内存块填充函数)

sql注入数据库原理详解

看完这100个客户需求,我终于知道企业文档管理的秘密

如何组装一个注册中心
随机推荐
Kotlin 值类 - value class
积分简明笔记-第二类曲线积分的类型
Flutter 环境变量配置和flutter doctor中的错误解决
One article to understand twenty kinds of switching power supply topologies
ClickHouse
Scala
详解JVM垃圾回收
2022/07/29 学习笔记 (day19)异常处理
ACL 2022 | 引入角度margin构建对比学习目标,增强文本语义判别能力
Activating data potential Amazon cloud technology reshapes cloud storage "family bucket"
研发人员的悲剧——“庞氏骗局”
leetcode经典问题——11.盛水最多的容器
js柯里化
基于SSM开发实现校园疫情防控管理系统
The blockbuster IP that has been popular in the world for 25 years, the new work has become a script paradise
Judging from the Internet:
蓝牙技术|了解蓝牙LE Audio的Auracast广播音频
ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]
hcip第八天
ant-design form form verification upload component (with personal packaged upload component)