首页 > 解决方案 > 如何使用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++ 中的一些方法,以便我可以按照上面代码中提到的方式进行确切的操作。我搜索了很多,但我不能完全满足我的需要。有人可以建议我获得它的方法。提前致谢。

标签: c++wmi

解决方案


Microsoft 提供了有关如何在此处执行此操作的非常全面的文档。

您基本上必须使用 COM 来启动您需要的所有对象类型,调用查询,然后在最后显式清理。这很混乱,但它有效。


推荐阅读