c++ - 如何使用c++实现wmi类的链接?
问题描述
我有一个示例代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
namespace WMIIRQ
{
class Program
{
static void Main(string[] args)
{
foreach(ManagementObject Memory in new ManagementObjectSearcher(
"select * from Win32_DeviceMemoryAddress").Get())
{
Console.WriteLine("Address=" + Memory["Name"]);
// associate Memory addresses with Pnp Devices
foreach(ManagementObject Pnp in new ManagementObjectSearcher(
"ASSOCIATORS OF {Win32_DeviceMemoryAddress.StartingAddress='" + Memory["StartingAddress"] + "'} WHERE RESULTCLASS = Win32_PnPEntity").Get())
{
Console.WriteLine(" Pnp Device =" + Pnp["Caption"]);
// associate Pnp Devices with IRQ
foreach(ManagementObject IRQ in new ManagementObjectSearcher(
"ASSOCIATORS OF {Win32_PnPEntity.DeviceID='" + Pnp["PNPDeviceID"] + "'} WHERE RESULTCLASS = Win32_IRQResource").Get())
{
Console.WriteLine(" IRQ=" + IRQ["Name"]);
}
}
}
Console.ReadLine();
}
}
}
我对 c# 不熟悉,我从某个链接获得了这段代码,我需要 c++ 中的一些方法,以便我可以按照上面代码中提到的方式进行确切的操作。我搜索了很多,但我不能完全满足我的需要。有人可以建议我获得它的方法。提前致谢。
解决方案
Microsoft 提供了有关如何在此处执行此操作的非常全面的文档。
您基本上必须使用 COM 来启动您需要的所有对象类型,调用查询,然后在最后显式清理。这很混乱,但它有效。
推荐阅读
- java - 调整行高没有按预期工作
- api - 如何在 Flutter 中创建 Web API?
- javascript - 使用 SheetJS 将动态创建的表格内容保存在 excel 文件中
- python-typing - 如何使用一组特定的值在 Python 中输入
- javascript - Firebase 功能不是实时的(?)
- python - XGBoost:提供分类类型时,DMatrix 参数 `enable_categorical` 必须设置为 `True`
- binance - 如何拍摄现有加密货币持有者的快照以提供 1:1 空投
- swift - 从自定义类创建的 NSTextField 随机出现
- css - 画布定位
- android - 在行/列 Jetpack Compose 中创建一个更大的项目