我的公司正試圖找出哪些機器沒有加載我們的圖像。我們在WMI中添加了一個名爲Revision_Detail的類,但由於不一致,它沒有在我們圖像的所有版本上填充。VBScript WMI類和屬性存在
我放在一起檢查Revision_Detail是否存在,然後檢查它是否爲空。如果它爲空,它會恢復到ImageRevision類,我們的每個圖像都有。
我的問題是我碰到(並正在使用)的函數,遍歷所有CIMV2類,並且有點慢。
有沒有辦法只是執行查詢並捕獲修訂細節不存在的錯誤?
Function WMIClassExists(strComputer, WMIClassName)
WMIClassExists = vbFalse
Dim objWMIService: Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim colClasses: Set colClasses = objWMIService.SubclassesOf()
Dim objClass
For Each objClass In colClasses
if instr(objClass.Path_.Path,WMIClassName) Then
WMIClassExists = vbTrue
End if
Next
Set objWMIService = Nothing
Set colClasses = Nothing
End Function
Set wshNetwork = WScript.CreateObject("WScript.Network")
strComputer = wshNetwork.ComputerName
If WMIClassExists(strComputer,"Revision_Detail") Then
'Found Revision_Detail
WSCript.Echo strWMIClass & " WMI class does exists on " & strComputer
Set Wmi = GetObject("winmgmts:\\" & strComputer & "\ROOT\CIMV2")
SET colItems = Wmi.ExecQuery("SELECT * FROM Revision_Detail")
For Each objItem in colItems
if IsNull(objItem.CurrentBuild) Then
'If CurrentBuild doesnt exist, check ImageRevision
SET colItems2 = Wmi.ExecQuery("SELECT * FROM ImageRevision")
For Each objItem2 in colItems2
wscript.echo "ImageRevision: " & objItem2.ImageRevision
Next
else
'Revision_Detail exists and is not blank
wscript.echo "CurrentBuild: " & objItem.CurrentBuild
wscript.echo "StartBuild: " & objItem.StartBuild
end if
Next
Else
'Must not be an our image
WSCript.Echo strWMIClass & " WMI class does not exists on " & strComputer
End if
我收到所需的對象: 'Revision_Detail(...)' 在此行 「Revision_Detail = GetWmiObjects(WMI, 」SELECT * FROM Revision_Detail「)」 –
哎呀,這是固定的。再試一次。 – Tomalak