gpt4 book ai didi

c++ - PropertyData 值数组

转载 作者:行者123 更新时间:2023-11-30 04:05:55 25 4
gpt4 key购买 nike

我正在尝试通过 wmi 查询获取特定值。我知道这个值本身存储在一个数组中,但我无法访问它。

ManagementObjectSearcher ^searcher =
gcnew ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive WHERE PNPDeviceID LIKE '" + marshal_as<String^>(DEV_FILTER) +"%'");

for each (ManagementObject ^drive in searcher->Get())
{
for each (ManagementObject ^o in drive->GetRelated("Win32_DiskPartition"))
{
for each (ManagementObject ^logDisk in o->GetRelated("Win32_LogicalDisk"))
{
Console::WriteLine(
"Disk: " + drive["Caption"]
+ "\n\tSize : " + drive["Size"]
+ "\n\tDriveLetter : " + logDisk["Name"]
+ "\n\t" + drive["PNPDeviceID"]
+ "\n\tSerialNumber: " + drive["SerialNumber"]
+ "\n\t" + drive["Capabilities"]
+ "\n\tRevision : " + drive["FirmwareRevision"]);
}
}
}

在调试调查中,我可以看到 drive["Capabilites"] 的每个值,但到目前为止我尝试过的所有内容,我都无法获得该数组的子值。

我想用 C++ 来做这个,感谢您的帮助。

最佳答案

要访问这些值,您必须转换属性和数组,然后遍历元素。试试这个 C++ CLI 示例代码。

#include "stdafx.h"
#using <system.management.dll>


using namespace System;
using namespace System::Management;

int main(array<System::String ^> ^args)
{
ManagementObjectSearcher ^searcher =
gcnew ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive");

for each (ManagementObject ^drive in searcher->Get())
{
for each (ManagementObject ^o in drive->GetRelated("Win32_DiskPartition"))
{
for each (ManagementObject ^logDisk in o->GetRelated("Win32_LogicalDisk"))
{
Console::WriteLine(
"Disk: " + drive["Caption"]
+ "\n\tSize : " + drive["Size"]
+ "\n\tDriveLetter : " + logDisk["Name"]
+ "\n\t" + drive["PNPDeviceID"]
+ "\n\tSerialNumber: " + drive["SerialNumber"]
+ "\n\tRevision : " + drive["FirmwareRevision"]);
Console::WriteLine("Capabilities");
for each(UInt16 v in (array<UInt16>^)(drive->Properties["Capabilities"]->Value))
{
Console::WriteLine(v);
}
}
}
}
Console::ReadLine();
return 0;
}

关于c++ - PropertyData 值数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23084919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com