Please enable JavaScript to view this site.

Option Explicit

 

Const MaxCharsPerLine = 80

 

Dim Args

 

Dim EventLog, EventType, EventSource, EventCategory, EventID, EventUser, EventComputer, EventDate, EventMessage, EventMessageFormatted

 

Dim fso, FileHandle

Dim TempFilePath, TempFile, PrinterPath

 

wscript.echo "eventprint.vbs: Prints event log records on a networked laser printer"

 

' ========================================

' Define variables here:

' ========================================

 

TempFile        = "C:\WINDOWS\TEMP\EVENTSENTRY_PRINT.TMP"

TempFileFF        = "C:\WINDOWS\TEMP\EVENTSENTRY_FF.TMP"

 

' ========================================

 

' Make sure we have the right amount of arguments

Set args = Wscript.Arguments

If args.count < 10 Then

   wscript.echo "Not enough arguments:"

 wscript.echo "eventprint.vbs \\SERVER\PRINTSHARE EventLog EventType EventSource EventCategory EventID EventUser EventComputer EventDate EventMessage"

   wscript.quit(1)

End If

 

' Get Arguments

PrinterPath                = args(0)

EventLog                = args(1)

EventType                = args(2)

EventSource                = args(3)

EventCategory        = args(4)

EventID                = args(5)

EventUser                = args(6)

EventComputer        = args(7)

EventDate                = args(8)

EventMessage        = args(9)

 

' Format EventMessage

Dim EventMsgArray, Element, OneLine

 

EventMsgArray = Split(EventMessage, " ", -1, 1)

For Each Element In EventMsgArray

 

 If (Len(OneLine) + Len(Element)) > MaxCharsPerLine Then

         EventMessageFormatted = EventMessageFormatted & OneLine & vbCRLF

         OneLine = Element & " "

 Else

         OneLine = OneLine & Element & " "

 End If

Next

EventMessageFormatted = EventMessageFormatted & OneLine

 

' Create temporary text file

Set fso = CreateObject("Scripting.FileSystemObject")

Set FileHandle = fso.CreateTextFile(TempFile, True)

 

FileHandle.Write "Event Log:      " & EventLog & vbCRLF

FileHandle.Write "Event Type:     " & EventType & vbCRLF

FileHandle.Write "Event Source:   " & EventSource & vbCRLF

FileHandle.Write "Event Category: " & EventCategory & vbCRLF

FileHandle.Write "Event ID:       " & EventID & vbCRLF

FileHandle.Write "Event User:     " & EventUser & vbCRLF

FileHandle.Write "Event Computer: " & EventComputer & vbCRLF

FileHandle.Write "Event Date:     " & EventDate & vbCRLF

FileHandle.Write "Event Message: " & vbCRLF

FileHandle.Write EventMessageFormatted & vbCRLF & Chr(12)

 

FileHandle.Close

 

' Create FF temp file, required for laser printers

Set FileHandle = fso.CreateTextFile(TempFileFF, True)

FileHandle.Write Chr(12)

FileHandle.Close

 

' Send files to printer

fso.CopyFile TempFile, PrinterPath

fso.CopyFile TempFileFF, PrinterPath

 

' Delete temp files

fso.DeleteFile(TempFile)

fso.DeleteFile(TempFileFF)

 

Set fso = Nothing