意想不到的下一步

意想不到的下一步

我有一些代码可以告诉我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 的部分之前,脚本运行良好。

答案1

我相信你的问题是这一行:

If Err = 0 Then

似乎没有匹配的End If

可能需要在最后一次之前Next

正确缩进代码将帮助您避免将来出现此类问题。

编辑:再看一遍,你只是把最后一个写错了Next,而且End If顺序不对。把它们颠倒过来。

相关内容