Option Explicit
On Error Resume Next
Dim colour, bbdelay, strDetail, strDetailAll
Dim WindowsShell, objWMIService, colInstalledPrinters, BBConfigExtPath, objPrinter
Const BBTestName = "print"
strDetail = ""
strDetailAll = ""
colour = "green"
bbdelay = "+27"
BBConfigExtPath = "c:\Program Files\BBWin\tmp"
'=============================================================================
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select PortName,Location,Status,DetectedErrorState,Name from Win32_Printer where Name != 'Microsoft XPS Document Writer'")
For Each objPrinter in colInstalledPrinters
If objPrinter.DetectedErrorState = "9" Then
strDetail = "&red" & " " & objPrinter.Name & " is OFFLINE" & vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "6" Then
strDetail = "&red" & " " & objPrinter.Name & " has NO TONER" & vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "1" Then
strDetail = "&red" & " " & objPrinter.Name & " is in ERROR" & vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "4" Then
strDetail = "&red" & " " & objPrinter.Name & " has NO PAPER" & vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "8" Then
strDetail = "&red" & " " & objPrinter.Name & " is JAMMED" & vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "10" Then
strDetail = "&red" & " " & objPrinter.Name & " is Requesting Service" & vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "11" Then
strDetail = "&red" & " " & objPrinter.Name & " shows OUTPUT BIN IS FULL" & vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "0" Then
strDetailAll = "<tr><td>&green " & objPrinter.Name & "</td><td>" & objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" & vbCrLf & strDetailAll
End If
Next
Set colInstalledPrinters = Nothing
Set objWMIService = Nothing
StartDetailBuild()
SetPrintFinalStatus()
GetBBPath()
WriteFile()
Sub StartDetailBuild()
IF colour = "red" then
strDetail = "&red Printer Status:" & vbCrLf & vbCrLf & strDetail & vbCrLf
ElseIf colour = "green" then
strDetail = "&green Printer Status: All Printers are Online and Operational" & vbCrLf & vbCrLf & strDetail & vbCrLf
End If
End Sub
Sub SetPrintFinalStatus()
Select Case colour
Case "red"
strDetail = "red" & bbdelay & " " & Date & " " & Time & vbCrLf & vbCrLf & strDetail & vbCrLf
Case "yellow"
strDetail = "yellow" & bbdelay & " " & Date & " " & Time & vbCrLf & vbCrLf & strDetail & vbCrLf
Case "green"
strDetail = "green" & bbdelay & " " & Date & " " & Time & vbCrLf & vbCrLf & strDetail & vbCrLf
End Select
End Sub
Sub GetBBPath()
Set WindowsShell = WScript.CreateObject("WScript.Shell")
If IsObject(WindowsShell) Then Set WindowsShell = Nothing
End Sub
Sub WriteFile()
Dim oFSO, oFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(BBConfigExtPath & "\" & BBTestName , 8 , TRUE)
oFile.Write strDetail
oFile.Write "<table>" & vbCrLf & strDetailAll & vbCrLf & "</table>"
oFile.Close
If IsObject(oFSO) Then Set oFSO = Nothing
End Sub