Logging Windows Print events

Posted on 2012-08-31
Last Modified: 2012-09-06
I would like to know if it's possible to capture the fact that the contents of a OLE field was printed from the native application being used to view the OLE contents.

Example: A user opens a Word Document from an embedded or linked OLE field, prints that document, and then somewhere in the VBA code for that screen my MS Access app can see that something was just printed and ask the user to enter a few parameters to establish a log that a printed copy was made.

I could just ask every time the screen closed, "Did you pint it?"  Although that's going to get annoying very fast.

Is there anything happening in the bowels of Access or the operating system I could use as a reasonable trigger to ask the user to make a print log?
Question by:DavidSmithstein
    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    If this can be done from the OS, it is beyond me.

    About the best you may be able to do is log this if a user clicks a "Print" button.

    It would add the various pieces of info to a table, ...something roughly like this:

    Currentdb.execute "INSERT INTO YourTable (Field1, Field2, Field3,...)
    VALUES (value1, value2, value3,...)",dbfailonerror

    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    Author Comment

    Thanks, but that doesn't help me as i'm storing controlled documents, MS Word, .pdf. Excel, anything that is OLE enabled and would like to add a feature that helps the client know if any were printed so obsolete ones can be retrieved when needed.

    Accepted Solution


    Author Comment

    Almost, but not quite. Is it possible to query the Operational log of the PrintService?  When I modify the code to look in that folder, I get "0 logs searched" even though I can go into event viewer and see a print job (EventID 307) there from yersterday.

    Dim objObject As WbemScripting.SWbemObject
    Dim setObjectSet As WbemScripting.SWbemObjectSet
    Dim strServer As String
    Dim strWQL As String
    Dim svcServices As WbemScripting.SWbemServices
    Dim varInsertionString As Variant
    Dim Counter As Integer

    Counter = 0
    strServer = "."  ' This computer
    Set svcServices = GetObject("winmgmts:\\" & strServer & "\root\cimv2")

    strWQL = "SELECT * " & _
             "FROM Win32_NTLogEvent " & _
             "WHERE Logfile = ""Microsoft-Windows-PrintService/Operational"""
    Set setObjectSet = svcServices.ExecQuery(strWQL)

    For Each objObject In setObjectSet
       ' MsgBox "Category: " & objObject.Category
     If objObject.EventCode = "307" Then
        MsgBox "Found Print Job"
         MsgBox "Time Generated: " & objObject.TimeGenerated
        MsgBox "Time Written: " & objObject.TimeWritten
        Exit Sub
     End If
     Counter = Counter + 1
      '  MsgBox "CategoryString: " & objObject.CategoryString
      '  MsgBox "Computer Name: " & objObject.ComputerName
     '   MsgBox "Data: " & objObject.Data
     '   MsgBox "Event Code: " & objObject.EventCode
      '  MsgBox "Event Identifier: " & objObject.EventIdentifier
     '   For Each varInsertionString In objObject.InsertionStrings
     '       MsgBox "Insertion String: " & varInsertionString
     '   Next
     '   MsgBox "Logfile: " & objObject.Logfile
     '   MsgBox "Message: " & objObject.message
     '   MsgBox "Record Number: " & objObject.RecordNumber
     '   MsgBox "Source Name: " & objObject.SourceName
    '    MsgBox "Type: " & objObject.Type
    '    MsgBox "User: " & objObject.User

        Set objObject = Nothing
    Set setObjectSet = Nothing

    Set svcServices = Nothing
    MsgBox Counter & " logs searched"
    LVL 6

    Expert Comment

    to log all print events over a network look at event ID's

    "System 10: " or "System 307: "

    best way to use this is to look at SIEM software which you can use to correlate and automate it so each time an event occurs its correlated together

    Author Comment

    I was told by a programmer of event log software in England that:

    "I think the problem is that the log you're after isn't covered by the eventlog WMI provider, i.e. so far as I'm aware there is no way to get at that log via WMI. This is something that has caused me major headaches and really ticks me off about MS; it goes completely against the spirit of WMI.

    There is however another way to get at that log - look up the "Windows Event Log API"

    I'll I've been able to find is code on how to post a log to the event log, but nothing to simple read it, and hopefull limit the read based on a date range of just today.

    Author Closing Comment

    tested this code and I am able to read event logs on my Windows 7 computer using MS Access 2010

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now