Connecting Tech Pros Worldwide Forums | Help | Site Map

How can I determine the status of the default printer

Raymond Martin
Guest
 
Posts: n/a
#1: Nov 20 '05
How do I find out if the default printer is offline or online (or has a
paper jam)?



Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Nov 20 '05

re: How can I determine the status of the default printer


Hello,

"Raymond Martin" <raym198@bellsouth.net> schrieb:[color=blue]
> How do I find out if the default printer is offline or online (or has a
> paper jam)?[/color]

\\\
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/de...mi_classes.asp

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


Raymond Martin
Guest
 
Posts: n/a
#3: Nov 20 '05

re: How can I determine the status of the default printer


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?


"Herfried K. Wagner [MVP]" <hirf.nosp@m.activevb.de> wrote in message
news:#kSXDW$bDHA.616@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hello,
>
> "Raymond Martin" <raym198@bellsouth.net> schrieb:[color=green]
> > How do I find out if the default printer is offline or online (or has a
> > paper jam)?[/color]
>
> \\\
> 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:
>
>[/color]
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
wmi_classes.asp[color=blue]
>
> HTH,
> Herfried K. Wagner
> --
> MVP · VB Classic, VB .NET
> http://www.mvps.org/dotnet
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#4: Nov 20 '05

re: How can I determine the status of the default printer


Hello,

"Raymond Martin" <raym198@bellsouth.net> schrieb:[color=blue]
> 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?[/color]

http://groups.google.de/groups?ie=UT...efault+printer

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


Closed Thread


Similar Visual Basic .NET bytes