Watching a printer for events

Posted on 2004-11-09
Last Modified: 2010-04-23
Is there a way to watch a printer for events I would like to retreive the file name that was printed and attach it to an e-mail with a short message saying what to do with the print.

Question by:Corey2
    LVL 28

    Assisted Solution

    I don't think that you can get such info about file is being printed from the printer. (Also you can get it from your code).
    You can get info about printer status

    Private Enum PrinterStatus
            PrinterIdle = 3
            PrinterPrinting = 4
            PrinterWarmingUp = 5
        End Enum

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim strPrintServer As String
            strPrintServer = "localhost"
            Dim WMIObject As String, PrinterSet As Object, Printer As Object
            WMIObject = "winmgmts://" & strPrintServer
            PrinterSet = GetObject(WMIObject).InstancesOf("win32_Printer")
            For Each Printer In PrinterSet
                MsgBox(Printer.Name & ":  " & PrinterStatusToString(Printer.PrinterStatus))
            Next Printer
        End Sub

        Private Function PrinterStatusToString(ByVal ps As PrinterStatus) As String
            Dim s As String
            Select Case ps
                Case PrinterStatus.PrinterIdle
                    s = "waiting (idle)"
                Case PrinterStatus.PrinterPrinting
                    s = "printing"
                Case PrinterStatus.PrinterWarmingUp
                    s = "warming up"
                Case Else  
                    s = "unknown state"
            End Select
            PrinterStatusToString = s
        End Function
    LVL 5

    Accepted Solution

    Look here to take an overview of what happens with this:

    Then you can check the performance monitor to look for the events at the Spool Queue (or whatever is its name on your system, im Spanish). There you can find the most useful events.

    Check the vb help about the PerformanceCounter Class to know more about it.

    See you.

    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    What do you think about the solutions presented here Corey2???

    LVL 13

    Author Comment

    They both look good though I haven't had a chance to really check into it to make a decision on who deserves what point values.  Hopefully I will get a chance soon here.  Please bear with me.

    LVL 13

    Author Comment

    Unfortunately I haven't been able to explore the possibilities here.  So I am unable to pick the answer which would most fit my situation I am going to evenly split the points because both solutions look good.

    Thank you


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now