How can I determine the status of the default printer

  • Thread starter Thread starter Raymond Martin
  • Start date Start date
R

Raymond Martin

How do I find out if the default printer is offline or online (or has a
paper jam)?
 
Hello,

Raymond Martin said:
How do I find out if the default printer is offline or online (or has a
paper jam)?

\\\
Private Enum PrinterStatus
PrinterIdle = 3
PrinterPrinting = 4
PrinterWarmingUp = 5
' For more states see WMI docs.
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
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
///

Documentation of WMI classes:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_classes.asp

HTH,
Herfried K. Wagner
 
Thanks for this Herfried - it seems like a lot of work but I can follow the
example pretty well. Thanks for the link to the WMI documentation. One
thing - this example iterates thru all the available printers. How do I know
which one is the default printer?
 
Back
Top