+ Post New Thread
Results 1 to 1 of 1
Scripts Thread, Very Basic 'Print Logging' System in Coding and Web Development; Hello, This is a script to generate a CSV file based on the EventLog readings(System->EventCode 10 (Successful print)), it will ...
  1. #1
    dwhyte85's Avatar
    Join Date
    Mar 2009
    Location
    Berkshire
    Posts
    1,232
    Thank Post
    162
    Thanked 151 Times in 136 Posts
    Rep Power
    104

    Smile Very Basic 'Print Logging' System

    Hello,

    This is a script to generate a CSV file based on the EventLog readings(System->EventCode 10 (Successful print)), it will obviously mean you need to alter your EventLogging settings to allow for capturing as many events as you want to log (eg, up the filesize limit / manually delete).

    I'm not suggesting I wrote much of this and it has a fatal flaw, it doesn't query the TimeGenerated date through WMI, it instead uses a crude comparison - so it's a bit wasteful and could be tweaked, it also relies on all printers are your printserver, it doesn't connect remotely although you could alter the code as necessary.

    You can alter where you save to, the filename etc in the code - it's not the best code in the world... but it's free and it does do what it is supposed to :-P.

    See below for code:

    Code:
    Private Function GetVBDate(DateTime)  
    GetVBDate =  DateSerial(left(DateTime,4),mid(DateTime,5,2),mid(DateTime,7,2))    
    End Function  
    'get wmi date to vbdate
    
    
    Dim objFso, objFolder, objWMI, objEvent ' Objects
    Dim strFile, strComputer, strFolder, strFileName, strPath ' Strings
    Dim intEvent, intNumberID, intRecordNum, colLoggedEvents
    dim theDate, startDate, endDate, temp1, temp2
    ' --------------------------------------------
    ' Set your variables
    intNumberID = 10 ' Event ID Number
    intEvent = 1
    intRecordNum = 1
    strComputer = "."
    'alter as necessary
    strFileName = "\PrintReport.csv"
    strFolder = "C:\PrintReports"
    strPath = strFolder & strFileName
    startDate = inputbox("Please Enter Start Date (first date of printing) in DD/MM/YYYY format")
    endDate = inputbox("Please Enter End Date (last date of printing) in DD/MM/YYYY format")
    ' ----------------------------------------
    ' Section to create folder to hold file.
    Set objFso = CreateObject("Scripting.FileSystemObject")
    If objFSO.FolderExists(strFolder) Then
        Set objFolder = objFSO.GetFolder(strFolder)
    Else
       Set objFolder = objFSO.CreateFolder(strFolder)
       Wscript.Echo "Folder created " & strFolder
    End If
    Set strFile = objFso.CreateTextFile(strPath, True)
    '--------------------------------------------
    ' Next section creates the file to store Events
    ' Then creates WMI connector to the Logs
    Set objWMI = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    Set colLoggedEvents = objWMI.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'System'" )
    intEvent = 1
    strFile.WriteLine "Date, DocName, User, Printer, IP/USB, Pages"
    
    For Each objEvent in colLoggedEvents
    If (objEvent.EventCode = intNumberID) Then
    theDate = getVBDate(objEvent.TimeGenerated)
    theDate = formatDateTime(theDate, vbShortDate)
    startDate = formatDateTime(startDate, vbShortDate)
    endDate = formatDateTime(endDate, vbShortDate)
    if ((theDate >= startDate) AND (theDate <= endDate)) Then
    temp1 = theDate&"::"& objEvent.Message
    temp1 = replace(temp1, " owned by ","::")
    temp1 = replace(temp1, " was printed on ","::")
    temp1 = replace(temp1, " via port ", "::")
    temp1 = replace(temp1, ".  Size in bytes: ", "::")
    temp1 = replace(temp1, "; pages printed: ","::")
    temp1 = replace(temp1, ",", "")
    temp1 = replace(temp1, "::",",")
    
    temp2 = split(temp1,",")
    temp1 = temp2(0)&","&temp2(1)&","&temp2(2)&","&temp2(3)&","&temp2(4)&","&temp2(6)
    strFile.WriteLine temp1
    intRecordNum = intRecordNum +1
    End If
    End if
    IntEvent = intEvent +1
    theDate = ""
    Next
    Wscript.Echo "Complete, check folder."
    WScript.Quit
    Last edited by dwhyte85; 7th May 2009 at 10:03 AM.



SHARE:
+ Post New Thread

Similar Threads

  1. Papercut Print Logging Software
    By Mr_M_Cox in forum Network and Classroom Management
    Replies: 4
    Last Post: 7th April 2011, 12:33 PM
  2. Replies: 0
    Last Post: 15th March 2009, 01:40 PM
  3. Logging onto the network after logging on locally
    By frankybaloney in forum Windows
    Replies: 9
    Last Post: 10th October 2008, 01:17 PM
  4. Print Spooler shut off on print
    By jmair in forum Windows
    Replies: 2
    Last Post: 29th August 2008, 09:35 AM
  5. print manager logging jobs
    By alonebfg in forum Windows
    Replies: 7
    Last Post: 4th November 2006, 10:12 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •