We help IT Professionals succeed at work.
Get Started

I get an error when run this vbs

Last Modified: 2012-05-09

I get an error when run this vbs

Windows Script Host
Script:      C:\Log.vbs
Line:      46
Char:      5
Error:      Input past end of file
Code:      800A003E
Source:       Microsoft VBScript runtime error

Can i get a refesh new file created each time i run. overrite the old file.


Dim data, tokens, fso, folder, files, sFolder, user, machine
Dim i, lines, row, objExcel, objSheet, objFileSystem, objInputFile
Const xlExcel7 = 39
Const EXCEL_OUTPUT_FILE = "d:\output.xls"
Const UNC_SOURCE_FOLDER = "\\s01\ger\LOGS"

row = 2

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
If (Err.Number <> 0) Then
    On Error GoTo 0
    WScript.Echo "Excel application not found."
End If
On Error GoTo 0

' Create a new workbook.

Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

objSheet.Cells(1, 1).Value = "Machines"
objSheet.Cells(1, 2).Value = "Users"
objSheet.Cells(1, 3).Value = "Data"

  Set fso = CreateObject("Scripting.FileSystemObject")

  Set folder = fso.GetFolder(UNC_SOURCE_FOLDER)
  Set files = folder.files
  For Each folderIdx In files
    'WScript.Echo "file: " & folderIdx.Name
    tokens = Split(folderIdx.Name, "_")
    machine = tokens(0)
    user = Replace(tokens(1), ".txt", "")
    'WScript.Echo "machine: " & machine
    Set objFileSystem = CreateObject("Scripting.fileSystemObject")
    Set objInputFile = objFileSystem.OpenTextFile(folderIdx, 1)
    lines = Split(objInputFile.ReadAll, vbNewLine)
    For i = 0 To UBound(lines)
        Line = lines(i)
        If InStr(Line, "ERROR:  Unable to get current user's SID") > 0 Then
            data = "Unable to get current user's SID"
            If InStr(Line, "Registry for current profile list backed up to:") > 0 Then
                data = Line
                If i + 2 <= UBound(lines) And InStr(lines(i + 2), "Operation complete") > 0 Then
                    data = data & " Operation complete"
                    i = i + 2
                End If
                If InStr(Line, "Operation complete") > 0 Then
                    data = "Operation complete"
                End If
            End If
        End If
'    WScript.Echo "data: " & data
 '   WScript.Echo

    objSheet.Cells(row, 1).Value = machine
    objSheet.Cells(row, 2).Value = user
    objSheet.Cells(row, 3).Value = data
    row = row + 1
objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs EXCEL_OUTPUT_FILE, xlExcel7
objExcel.ActiveWorkbook.Close False

' Quit Excel.

Set objSheet = Nothing
Set objExcel = Nothing

Open in new window

Watch Question
Most Valuable Expert 2011
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE