Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > how to check local or network printer status
 

how to check local or network printer status

Hi!

I would like to check the status of local or network printer before printing.

The below code doesn't work well, gives wrong status especially on network printer.

Thanks in advance. 

Dim strComputer = "."

Dim objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Dim colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
Dim objprinter
Dim strprinterstatus As String = Nothing

For
Each objprinter In colInstalledPrinters
If objprinter.default() Then

Select Case objprinter.PrinterStatus

Case 1

strprinterstatus = "Other"

Case 2
strprinterstatus = "Unknown"
Case 3
strprinterstatus = "Idle"
Case 4
strprinterstatus = "Printing"
Case 5
strprinterstatus = "Warming up"

End Select

End If

Next

 

 

 

 

Echo Box  Tuesday, October 13, 2009 8:31 AM
Hi Echo,

I think you  can try the following code, it can check the status of all available printer.
'Imports System.Drawing.Printing
Public Class Form1
    Private Enum PrinterStatus
        PrinterIdle = 3
        PrinterPrinting = 4
        PrinterWarmingUp = 5
    End Enum
    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 ' Vielleicht gibt es noch weitere Fälle...
                s = "unknown state"
        End Select
        Return s
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strPrintServer As String = "localhost"
        Dim WMIObject As String = "winmgmts://" & strPrintServer
        Dim PrinterSet As Object = GetObject(WMIObject).InstancesOf("win32_Printer")
        'Get default printer name
        'Dim printDocument1 As PrintDocument = New PrintDocument()
        'MessageBox.Show(printDocument1.PrinterSettings.PrinterName)
        For Each Printer As Object In PrinterSet
            ListBox1.Items.Add(Printer.Name & ": " & PrinterStatusToString(Printer.PrinterStatus))
        Next Printer
    End Sub
End Class
I found it at the following link
http://bytes.com/topic/visual-basic-net/answers/347497-how-can-i-determine-status-default-printer

Hope this helps

Regards
Jeff Shan
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Jeff Shan  Friday, October 16, 2009 7:59 AM
Malange  Tuesday, October 13, 2009 1:58 PM
Hi Echo,

I think you  can try the following code, it can check the status of all available printer.
'Imports System.Drawing.Printing
Public Class Form1
    Private Enum PrinterStatus
        PrinterIdle = 3
        PrinterPrinting = 4
        PrinterWarmingUp = 5
    End Enum
    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 ' Vielleicht gibt es noch weitere Fälle...
                s = "unknown state"
        End Select
        Return s
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strPrintServer As String = "localhost"
        Dim WMIObject As String = "winmgmts://" & strPrintServer
        Dim PrinterSet As Object = GetObject(WMIObject).InstancesOf("win32_Printer")
        'Get default printer name
        'Dim printDocument1 As PrintDocument = New PrintDocument()
        'MessageBox.Show(printDocument1.PrinterSettings.PrinterName)
        For Each Printer As Object In PrinterSet
            ListBox1.Items.Add(Printer.Name & ": " & PrinterStatusToString(Printer.PrinterStatus))
        Next Printer
    End Sub
End Class
I found it at the following link
http://bytes.com/topic/visual-basic-net/answers/347497-how-can-i-determine-status-default-printer

Hope this helps

Regards
Jeff Shan
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Jeff Shan  Friday, October 16, 2009 7:59 AM

You can use google to search for other answers

Custom Search

More Threads

• ToolBox - Empty???
• importin data from an access database to another access database using VB
• COM Component Creation
• Whats with SQL Sever currently?
• Copy SQLEX DB from Template
• web service error
• free obfuscator for express version
• Projects wont debug and I get no error message
• How to use UTF-8 above 128!
• How to open a specifided folder in the windows explore?