Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer Log from Event Viewer > System

Status
Not open for further replies.

gk17

Technical User
Sep 6, 2013
86
US
Hi,

I know there is a printer log where we can get from the Event Viewer > System but I need the description themselves. I found a script to do this here but seems to need some tweaking.

Code:
Const ForWriting = 2
 strComputer = "."
 strLogfile = "C:\print.CSV"
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objLogFile = objFSO.CreateTextFile(strLogfile, ForWriting, True)
 Set objWMIService = GetObject("winmgmts:{(Security)}\\" & strComputer & "\root\cimv2")
 Set colEvents=objWMIService.ExecQuery("Select * from Win32_NTLogEvent WHERE EventCode=10 And SourceName='Microsoft-Windows-PrintSpooler'")

 For Each objEvent in colEvents
 Job1=ptrEnd(objEvent.Message,", ")
 Job2=ptrStart(objEvent.Message," owned by ")
 User1=ptrEnd(objEvent.Message," owned by ")
 User2=ptrStart(objEvent.Message," was printed on ")
 Queue1=ptrEnd(objEvent.Message," was printed on ")
 Queue2=ptrStart(objEvent.Message," through port") 
 Pages1=ptrEnd(objEvent.Message,"Pages printed: ")
 Pages2=Instr(Pages1,objEvent.Message,".")
 strJob=Mid(objEvent.Message,Job1,Job2-Job1)
 strUser=Mid(objEvent.Message,User1,User2-User1)
 strQueue=Mid(objEvent.Message,Queue1,Queue2-Queue1)
 numPages=CInt(Mid(objEvent.Message,Pages1,Pages2-Pages1))
 strDetails=Chr(34) & WMIDateStringToDate(objEvent.TimeWritten) & Chr(34) & "," 
 strDetails=strDetails & Chr(34) & strQueue & Chr(34) & ","
 strDetails=strDetails & Chr(34) & strJob & Chr(34) & ","
 strDetails=strDetails & Chr(34) & strUser & Chr(34) & ","
 strDetails=strDetails & Chr(34) & numPages & Chr(34)
 WScript.Echo strDetails
 objLogFile.WriteLine strDetails
 Next
 objLogFile.Close
 
 Function WMIDateStringToDate(dtmBootup)
     WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
          Mid(dtmBootup, 7, 2) & "/" &       Left(dtmBootup, 4) _
          & " " & Mid (dtmBootup, 9, 2) & ":" & _
          Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
          13, 2))
End Function
 
Function ptrEnd(strSource, strSearch)
  ptrEnd=InStr(1,strSource,strSearch,0)+Len(strSearch)
End Function
 
Function ptrStart(strSource, strSearch)
  ptrStart=InStr(1,strSource,strSearch,0)
End Function

Not good with VBS but I tried changing (Security) to (System) and got an error. I also tried replacing the 5th and 6th lines with the following instead which I got from MSDN without any success:

Code:
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent " _
        & "Where Logfile = 'System'")

If I can get the above working, it will let me see all the details for all the print jobs on this server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top