Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "Status"
objExcel.Cells(1, 3).Value = "Error Number"
objExcel.Cells(1, 4).Value = "Hex Error Number"
objExcel.Cells(1, 5).Value = "Error Description"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\Wmi")
objExcel.Cells(intRow, 1).Value = UCase(strComputer)
If Err.Number <> 0 Then
objExcel.Cells(intRow, 2).Value = "Error"
objExcel.Cells(intRow, 3).Value = Err.Number
objExcel.Cells(intRow, 4).Value = Hex(Err.Number)
ElseIf Err.Number = 0 Then
objExcel.Cells(intRow, 2).Value = "Success"
objExcel.Cells(intRow, 5).Value = "No Errors"
Err.Clear
End If
If Err.Number = 462 Then
objExcel.Cells(intRow, 5).Value = "Machine Not Found"
ElseIf Err.Number = "-2147217394" Then
objExcel.Cells(intRow, 5).Value = "WMI Class Not Found"
ElseIf Err.Number = "-2147217405" Then
objExcel.Cells(intRow, 5).Value = "Access Denied"
Err.Clear
End If
If objExcel.Cells(intRow, 2).Value = "Error" Then
objExcel.Cells(intRow, 2).Font.ColorIndex = 3
Else
objExcel.Cells(intRow, 2).Font.ColorIndex = 10
End If
intRow = intRow + 1
Loop
objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
MsgBox "Done"
-------------------
Thanks,
http://paddymaddy.blogspot.com/
0 comments:
Post a Comment