Next Inesperado

0

Eu tenho um código que me diz unexpected Next on line 131 . Embora se eu excluir isso, isso me diz expected Next on line 131 . Eu só quero ser capaz de digitalizar um intervalo de endereços IP e retornar as informações abaixo, enquanto exporta para um .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")

Observe que, se eu alterar isso para um único computador, não tenho problemas. O script foi ótimo até eu adicionar a parte sobre IPs.

    
por Christopher Collins 06.07.2018 / 16:40

1 resposta

1

Eu acredito que seu problema é esta linha:

If Err = 0 Then

que parece não ter correspondência End If

Pode ser necessário ir antes do último Next

Recuar corretamente seu código ajudará você a evitar esse tipo de problema no futuro.

Editar: no segundo olhar, você tem apenas os últimos Next e End If na ordem errada. Reverta-os.

    
por 06.07.2018 / 16:51