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."
WScript.Quit
End If
On Error GoTo 0
' Create a new workbook.
objExcel.Workbooks.Add
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"
Else
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
Else
If InStr(Line, "Operation complete") > 0 Then
data = "Operation complete"
End If
End If
End If
Next
' 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
Next
objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs EXCEL_OUTPUT_FILE, xlExcel7
objExcel.ActiveWorkbook.Close False
' Quit Excel.
objExcel.Application.Quit
Set objSheet = Nothing
Set objExcel = Nothing
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.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE