Solved

checking status of printer in vb.net

Posted on 2004-04-15
3
1,102 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 125 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

23 Experts available now in Live!

Get 1:1 Help Now