本文介绍了将数组中的属性字符串解析为 For Each 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 VBScript 获取有关笔记本电脑电池的信息.
I am trying to get information about the battery in my laptop by using VBScript.
这是更多的属性.我想为每个 objItem
解析 arrayItems("Name","Availability","BatteryStatus","Chemistry")
.
It is more properties. I want to parse arrayItems("Name","Availability","BatteryStatus","Chemistry")
for each objItem
.
例如:
For iii = 0 To UBound(arrayItems)
WScript.Echo "Result of iii:" & objItem.arrayItems (iii)
Next
我不想手动输入 "Availability:" &objItem.Availability
, "BatteryStatus:" &objItem.BatteryStatus
, ...
I do not want to enter manually as "Availability: " & objItem.Availability
, "BatteryStatus: " & objItem.BatteryStatus
, ...
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery",,48)
For Each objItem In colItems
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Availability: " & objItem.Availability
WScript.Echo "BatteryStatus: " & objItem.BatteryStatus
WScript.Echo "Chemistry: " & objItem.Chemistry
WScript.Echo "DesignVoltage: " & objItem.DesignVoltage
WScript.Echo "EstimatedChargeRemaining: " & objItem.EstimatedChargeRemaining
WScript.Echo "Status: " & objItem.Status
Next
推荐答案
你想要的可以通过对象的 properties_
属性集:
What you want can be done via the object's properties_
property set:
arrayItems = Array("Name", "Availability", "BatteryStatus", "Chemistry")
For Each objItem In colItems
For Each name In arrayItems
WScript.Echo name & ": " & objItem.properties_(name)
Next
Next
这篇关于将数组中的属性字符串解析为 For Each 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!