Solved

checking status of printer in vb.net

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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