2010-11-23 9 views
5

:VBScript'te bir WMI nesnesinin özelliklerine NAME BY tarafından erişilebiliyor? Bunun yerine böyle bir kod

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 

bu sözdizimlerinden biri gibi, adıyla şey her özelliğe erişmek için mümkün mü: daha iyi

Wscript.Echo "Age: " & objItem("Age") 
Wscript.Echo "Age: " & objItem.Properties("Age") 
Wscript.Echo "Age: " & objItem.Item("Age") 

Ve, yapabileceğiniz herhangi bir yolu yoktur gibi bir şey:

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 

cevap

7

Sen Properties_ özellik aracılığıyla WMI nesnelerin özelliklerini adlı erişebilirsiniz:

objItem.Properties_("Age") 
objItem.Properties_.Item("Age") 

Ve tabii ki, aynı zamanda Properties_ koleksiyonunu numaralandırabilmesidir:

For Each objItem in colItems 
    For Each prop in objItem.Properties_ 
    If IsArray(prop) Then 
     WScript.Echo prop.Name & ": " & Join(prop, ", ") 
    Else 
     Wscript.Echo prop.Name & ": " & prop 
     ''# -- or -- 
     ''# Wscript.Echo prop.Name & ": " & prop.Value 
    End If 
    Next 
Next 
İlgili konular