3
我有一個從txt文件中讀取主機名的程序,它掃描網絡中的主機名,然後顯示主機名及其各自的Windows操作系統(CAPTION)。For循環中的變量保留舊值
我想讓所有的Windows XP機器升級到Windows 7.我試圖運行這個列表來給我一個想法,我已升級了多少臺機器,以及我還有多少升級的想法,等
問題是,如果腳本試圖聯繫主機名是一個不良主機或者如果主機名是關閉的,則使用語句On Error Resume Next
它會顯示最後一個主機名的操作系統。然後,每個正在掃描的名稱都顯示相同的操作系統。
什麼可能導致此錯誤?
On Error Resume Next
const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile= objFSO.OpenTextFile _
("C:\users\bh\desktop\hostnames.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.close
arrComputers = Split(strText, vbCrlf)
for Each strComputer in arrComputers
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
Wscript.Echo strComputer & ": " & objOperatingSystem.Caption
Next
Next