Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

checking status of printer in vb.net

Posted on 2004-04-15
3
Medium Priority
?
1,171 Views
Last Modified: 2013-10-21
Can someone show me some code that allows me to check the status of an attached printer. I need to know when the print queue is empty, or when the printer is finished printing.

Thanks,
Rut
0
Comment
Question by:rutledgj
3 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 10834131
add reference to System management

Imports System.Management


    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
0
 

Author Comment

by:rutledgj
ID: 10835931
This solution worked great but I got an error trying to import system.management. I just left it out and it worked.
0
 

Expert Comment

by:sphairos
ID: 39590080
Hi

I tried your code and it's working well, but when I want to check wether the status is changing while I pass it from "idle" to "printing" it still does display "idle" despite the printer is "printing"...

What did I miss ?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

885 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