Check Printer Status??? How??

  • Thread starter Thread starter Vanessa
  • Start date Start date
V

Vanessa

Hi,
I'm trying to select a printer in the system printers collection. I'm able
to do this.

However, if the printer is a network printer and happens that this printer
is not on or not ready, I won't be able to know and I try to print a
document I will get an error.

Is there anyway that I can check the status for the printer that the user
select is ready or not?

Regards
Vanessa
 
* "Vanessa said:
I'm trying to select a printer in the system printers collection. I'm able
to do this.

However, if the printer is a network printer and happens that this printer
is not on or not ready, I won't be able to know and I try to print a
document I will get an error.

Is there anyway that I can check the status for the printer that the user
select is ready or not?

\\\
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
PrinterStatusToString = 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
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
Back
Top