如何从对象中的项目中获取值?
How to get the values from Items within Object?
我有以下代码和查询以从 Wlan 连接获取 Sent/Received 字节。我想获取每个属性项的值,但在尝试这样时我得到 Generic failure
:
a = WMIvalues.Item(1).Properties_.Item(1).Value
正确的做法是什么?
Sub Test()
Dim WMIvalues As Object
Dim sWQL As String
sWQL = "Select BytesReceivedPersec,BytesSentPersec,BytesTotalPersec from Win32_PerfRawData_Tcpip_NetworkInterface"
Set WMIvalues = GetObject("winmgmts:root/CIMV2").ExecQuery(sWQL)
a = WMIvalues.Item(1).Properties_.Item(1).Value
End Sub
这对我有用:
Dim WMIvalues As Object
Dim sWQL As String
Dim o As Object, i As Long
sWQL = "Select BytesReceivedPersec,BytesSentPersec,BytesTotalPersec from " _
"Win32_PerfRawData_Tcpip_NetworkInterface"
Set WMIvalues = GetObject("winmgmts:root/CIMV2").ExecQuery(sWQL)
i = 0
For Each o In WMIvalues
i = i + 1 'increment item counter variable
Debug.Print o.BytesReceivedPersec, o.BytesSentPersec, o.BytesSentPersec, o.BytesTotalPersec
'logic here based on i and the o properties...
Next o
参见:https://www.activexperts.com/admin/scripts/wmi/vbscript/0473/
我有以下代码和查询以从 Wlan 连接获取 Sent/Received 字节。我想获取每个属性项的值,但在尝试这样时我得到 Generic failure
:
a = WMIvalues.Item(1).Properties_.Item(1).Value
正确的做法是什么?
Sub Test()
Dim WMIvalues As Object
Dim sWQL As String
sWQL = "Select BytesReceivedPersec,BytesSentPersec,BytesTotalPersec from Win32_PerfRawData_Tcpip_NetworkInterface"
Set WMIvalues = GetObject("winmgmts:root/CIMV2").ExecQuery(sWQL)
a = WMIvalues.Item(1).Properties_.Item(1).Value
End Sub
这对我有用:
Dim WMIvalues As Object
Dim sWQL As String
Dim o As Object, i As Long
sWQL = "Select BytesReceivedPersec,BytesSentPersec,BytesTotalPersec from " _
"Win32_PerfRawData_Tcpip_NetworkInterface"
Set WMIvalues = GetObject("winmgmts:root/CIMV2").ExecQuery(sWQL)
i = 0
For Each o In WMIvalues
i = i + 1 'increment item counter variable
Debug.Print o.BytesReceivedPersec, o.BytesSentPersec, o.BytesSentPersec, o.BytesTotalPersec
'logic here based on i and the o properties...
Next o
参见:https://www.activexperts.com/admin/scripts/wmi/vbscript/0473/