5
,而不是像這樣的代碼:可能在VBScript中訪問WMI對象的屬性BY NAME?
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_IP4RouteTable",,48)
For Each objItem in colItems
Wscript.Echo "Age: " & objItem.Age
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Next
是否有可能通過名稱來訪問每個屬性,像這些語法之一:
Wscript.Echo "Age: " & objItem("Age")
Wscript.Echo "Age: " & objItem.Properties("Age")
Wscript.Echo "Age: " & objItem.Item("Age")
更妙的是,有沒有什麼辦法可以做到是這樣的:
Dim colItems
Dim objItem
Dim aProperty
Set colItems = objWMIService.ExecQuery("Select * from Win32_IP4RouteTable",,48)
For Each objItem in colItems
For Each aProperty in objItem.Properties
Wscript.Echo aProperty.Name & ": " & objItem(aProperty.Name)
Next
Next