הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Monday, May 3, 2010 3:53 PM
hi,
How to check the printer status before printing the report. i am using print dialog to print the report. i want to check the printer is on or off or printer is ready before report is send to printer.
i want to insert a function that check the selected printer status when user click on the print button. if printer works fine then print report else alert the user to set the printer.
please help me with the code or resource link?
Thanks in advance
regards
sharmile
All replies (7)
Monday, May 3, 2010 4:14 PM ✅Answered | 1 vote
Hi sharmile,
yes you can check the printer status. Here you can get a reference for the following code (at the page - W32 -> Printer..)
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
return "idle"
Case PrinterStatus.PrinterPrinting
return "printing"
Case PrinterStatus.PrinterWarmingUp
return "warmup"
Case Else
return "unknown"
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
Dim PrinterSet As Object
Dim Printer As Object
WMIObject = "winmgmts://" & strPrintServer
PrinterSet = GetObject(WMIObject).InstancesOf("win32_Printer")
For Each Printer In PrinterSet
MsgBox( _
Printer.Name & ": " & _
PrinterStatusToString(Printer.PrinterStatus) _
)
Next
End Sub
ExtendedPrinterStatus
Data type: uint16
Access type: Read-only
Status information for a printer that is different from information specified in the Availability property.
Value | Meaning |
---|---|
1 (0x1) | Other |
2 (0x2) | Unknown |
3 (0x3) | Idle |
4 (0x4) | Printing |
5 (0x5) | Warming Up |
6 (0x6) | Stopped Printing |
7 | Offline |
8 (0x8) | Paused |
9 (0x9) | Error |
10 (0xA) | Busy |
11 (0xB) | Not Available |
12 (0xC) | Waiting |
13 (0xD) | Processing |
14 (0xE) | Initialization |
15 | Power Save |
16 (0x10) | Pending Deletion |
17 (0x11) | I/O Active |
18 (0x12) | Manual Feed |
Regards
Martinwy
Monday, May 10, 2010 7:30 AM ✅Answered
Hello sharmile,
Thanks for your post.
Here is an example about how to check the printer is offline or online prior to printing.
Hope it helps.
http://kellychronicles.spaces.live.com/blog/cns!A0D71E1614E8DBF8!465.entry?sa=918839463
If you have any problems,please feel free to follow up.
Best regards,
Liliane
Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
Tuesday, May 4, 2010 3:24 AM
Hi Martinwy,
Thank you very much for the code and explanation. i tried ur code its working well.
I will apply this to my required application and let you know.
Best Regards,
Sharmile
Tuesday, May 4, 2010 12:04 PM
HI,
i have tried the code with network printers. i am getting the printers names. but problem occur for the printer that is office line (i have add offline to enum declaration) . unknown is only detected when the pritner connected mechine is switch off not for the printer is switched off.
i also tired with the "ExtendedDetectedErrorState" to detect no paper. but code didn't detect the status.
pls help me with a solution to this problem
Best regards,
sharmile
Monday, May 10, 2010 10:25 AM
Hello sharmile,
Sorry for the delay. When you come back, you could have a try. If you have any problems, please feel free to follow up.
Now in order to facilate the forum, I marked the helpful replies as answer.
If you think they provide no help, please unmark. Thanks.
Best regards,
Liliane
Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
Wednesday, June 27, 2012 10:45 PM
Hi, this is great & almost what I need however it doesn't work when you switch your project to Options strict, in other words this solution relies on the WMIObject to be late bound.
Is there a way to do the same thing with early bound objects, so that it works when Option Strict is on?
Many thanks for any ideas
@nt
@nt
Monday, March 11, 2013 6:04 PM
I am trying to get get the status of a specific printer stored as a variable so something happens when it is printer, or idling, etc. I am able to retrieve the status of all the printer connected to my PC(see code below). How to I set the status of a Pinter as a variable?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strPrintServer As String, WMIObject As String, PrinterSet As Object, Printer As Object
strPrintServer = "localhost"
WMIObject = "winmgmts://" & strPrintServer
PrinterSet = GetObject(WMIObject).InstancesOf("win32_Printer")
For Each Printer In PrinterSet
MsgBox(Printer.Name & ": " & (Printer.PrinterStatus))
Next Printer
End Class