У меня есть некоторый код, который сообщает мне unexpected Next on line 131
. Хотя, если я удаляю это, он говорит мне, что expected Next on line 131
. Я просто хочу иметь возможность сканировать диапазон IP-адресов и возвращать приведенную ниже информацию при экспорте в .csv.
' NetworkFindInfo.vbs - Windows Logon Script.
' VBScript - Look up a computers info.
' Author Chris Collins
' Version 1 - July 2018
' ----------------------------------------------------------'
' Define variables.
dim strInputPath, strOutputPath, strStatus
dim objFSO, objTextIn, objTextOut
' Constants for FileSystemObject
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8
strInputPath = "E:\VBScripts\TestFolder\computerlist.txt" '- location of input
strOutputPath = "E:\VBScripts\TestFolder\ComputerInfo.csv" '- location of output
'Create a Script Runtime FileSystemObject.
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objTextIn = objFSO.OpenTextFile( strInputPath,1 )
'Step 1 - Check to see if the output file exists. If so, open it for writing or appending.
'If not, create it and open it for writing.
If objFSO.FileExists(strOutputPath) Then
Set objOutputFile = objFSO.OpenTextFile (strOutputPath, FOR_WRITING)
Else
Set objOutputFile = objFSO.CreateTextFile(strOutputPath)
End If
If Err <> 0 Then
Wscript.Echo "Unable to open " & strOutputPath & " for output."
WScript.Quit
End If
'Create Headers for Host, NIC, IP and SubNet Mask
objOutputFile.Writeline "OS, Processor/System Architecure, Computer Name, Total Physical Memory, Serial/Service, Processor Name, NIC, IP Address, Computer Name, NIC, MAC Address"
Do until objTextIn.AtEndOfStream = True
strComputer = objTextIn.ReadLine
'Step 3 - Collect Computer Inforamtion
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery("SELECT * FROM " & _
"Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
' Test for success in binding to WMI.
If Err = 0 Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
Set colSMBIOS = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
Set colItems = objWMIService.ExecQuery(_
"Select * from Win32_Processor")
Set shell = CreateObject("WScript.Shell")
Set getOSVersion = shell.exec("%comspec% /c ver")
version = getOSVersion.stdout.readall
Select Case True
Case InStr(version, "n 5.0") > 1 : GetOS = "Windows 2000"
Case InStr(version, "n 5.1") > 1 : GetOS = "Windows XP"
Case InStr(version, "n 5.2") > 1 : GetOS = "Windows Server 2003"
Case InStr(version, "n 6.0") > 1 : GetOS = "Windows Vista"
Case InStr(version, "n 6.0.6001") > 1 : GetOS = "Windows Server 2008"
Case InStr(version, "n 6.1.7600") > 1 : GetOS = "Windows 7"
Case InStr(version, "n 6.1.7600.16385") > 1 : GetOS = "Windows Server 2008"
Case InStr(version, "n 6.1.7601") > 1 : GetOS = "Windows 7 SP1"
Case InStr(version, "n 6.2") > 1 : GetOS = "Windows 8"
Case InStr(version, "n 6.2.9200") > 1 : GetOS = "Windows Server 2012"
Case InStr(version, "n 6.3") > 1 : GetOS = "Windows 8.1"
Case InStr(version, "n 6.3.9200") > 1 : GetOS = "Windows Server 2012 R2"
Case InStr(version, "n 6.3.9600") > 1 : GetOS = "Windows Server 2012 R2"
Case InStr(version, "n 10.0.17134") > 1 : GetOS = "Windows 10 (1803)"
Case InStr(version, "n 10.0.16299") > 1 : GetOS = "Windows 10 (1709)"
Case InStr(version, "n 10.0.15063") > 1 : GetOS = "Windows 10 (1703)"
Case InStr(version, "n 10.0.14393") > 1 : GetOS = "Windows 10 (1607)"
Case InStr(version, "n 10.0.10586") > 1 : GetOS = "Windows 10 (1511)"
Case InStr(version, "n 10.0.10240") > 1 : GetOS = "Windows 10"
Case Else : GetOS = "Unknown"
End Select
'Step 4 check bitness (x64 or x86)
Dim WshShell
Dim WshProcEnv
Dim system_architecture
Dim process_architecture
Set WshShell = CreateObject("WScript.Shell")
Set WshProcEnv = WshShell.Environment("Process")
process_architecture= WshProcEnv("PROCESSOR_ARCHITECTURE")
If process_architecture = "x86" Then
system_architecture= WshProcEnv("PROCESSOR_ARCHITEW6432")
If system_architecture = "" Then
system_architecture = "x86"
End if
Else
system_architecture = process_architecture
End If
'Step 5 - Output Data to file
objOutputFile.Write GetOS
objOutputFile.Write "," & process_architecture & "-" & system_architecture
For Each objComputer in colSettings
objOutputFile.Write ", " & objComputer.Name
objOutputFile.Write ", " & Round(objComputer.TotalPhysicalMemory / 1073741824, 2) & "GB Usable"
Next
For Each objSMBIOS in colSMBIOS
objOutputFile.Write ", " & objSMBIOS.SerialNumber
Next
For Each objItem in colItems
objOutputFile.Write ", " & objItem.Name
Next
For Each objNicConfig In colNicConfigs
For Each strIPAddress In objNicConfig.IPAddress
objOutputFile.Write strComputer & ", (" & objNicConfig.Index & ") "& objNicConfig.Description & ", " & strIPAddress & ", " & strMACAddress
Next
Next
End If
loop
Msgbox("Done Collecting Data")
Обратите внимание, если я изменю это на один компьютер, у меня нет проблем. Сценарий работал отлично, пока я не добавил часть о IP.