Hi there
I have a bit of an issue surrounding printers. I need to be able to give my users a list of printer that they can print from. My users work in many different places and have access to all sorts of printer so therefore have quite a few installed on their PC. I want to be able to give them a list of all the printers on their computer that are 'Ready'.
I found a lovely bit of code to determine whether or not a printer is ready or not, however the refresh rate of this data is poor. By this i mean for example
I ran my program and printer1,printer2,printer3 were all idle (so ready)
then i went over to printer1 and turned it off, and then to printer2 and took all the paper out. then ran the program again and it all said idle again. only after i had tried to print to them did it then refresh and give me the correct errors.
What I would like to know is if there is any way i can refresh printer status' before running my code being able to give 'up to minute' printer status' before the user selects the printer.
this is my entire printer selector class
Ian
I have a bit of an issue surrounding printers. I need to be able to give my users a list of printer that they can print from. My users work in many different places and have access to all sorts of printer so therefore have quite a few installed on their PC. I want to be able to give them a list of all the printers on their computer that are 'Ready'.
I found a lovely bit of code to determine whether or not a printer is ready or not, however the refresh rate of this data is poor. By this i mean for example
I ran my program and printer1,printer2,printer3 were all idle (so ready)
then i went over to printer1 and turned it off, and then to printer2 and took all the paper out. then ran the program again and it all said idle again. only after i had tried to print to them did it then refresh and give me the correct errors.
What I would like to know is if there is any way i can refresh printer status' before running my code being able to give 'up to minute' printer status' before the user selects the printer.
this is my entire printer selector class
Code:
Imports System.Drawing.Printing
Public Class FrmPrinterSelector
Private _Printer As String
Public ReadOnly Property Printer As String
Get
Return _Printer
End Get
End Property
Private Enum PrinterStatus
Online = 0
PrinterIdle = 3
PrinterPrinting = 4
PrinterWarmingUp = 5
OutOfPaper = 144
ManualFeedInProgress = 160
Printing = 1024
LidOpen = 4194432
OutOfPaperLidOpen = 4194448
Initializing = 32768
Offline = 4096
' For more states see WMI docs.
End Enum
Private Sub FrmPrinterSelector_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim WMIObject As String, PrinterSet As Object, Printer As Object
WMIObject = "winmgmts://localhost"
PrinterSet = GetObject(WMIObject).InstancesOf("win32_Printer")
For Each Printer In PrinterSet
MsgBox(Printer.Name & ": " & PrinterStatusToString(Printer.PrinterStatus))
Next Printer
'For Each P As String In PrinterSettings.InstalledPrinters
' CboPrinters.Items.Add(P)
'Next
'CboPrinters.SelectedIndex = -1
End Sub
Private Sub BtnOk_Click(sender As System.Object, e As System.EventArgs) Handles BtnOk.Click
_Printer = CboPrinters.SelectedText
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
Private Sub BtnCancel_Click(sender As System.Object, e As System.EventArgs) Handles BtnCancel.Click
_Printer = ""
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Sub
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
s = "unknown state"
End Select
Return s
End Function
End Class