Makara
Makara

Reputation: 233

is there any code in vb.net to check printer status

The problem seen to appear again in printing job...

I have a printer(Epson TM-T88IV Receipt). Before printing, i would like to check if printer is available for printing or not (connect or not). if not, i will show the print preview form. otherwise it will print automatically

any solution in vb.net code

Thanks in advance
Makara

Upvotes: 0

Views: 11573

Answers (2)

Matt Wilko
Matt Wilko

Reputation: 27322

I'm not 100% sure this will work so try it first:

'usage
For Each prn As String In PrinterSettings.InstalledPrinters
    Debug.WriteLine(String.Format("Is printer {0} online? {1}", prn, CheckPrinter(prn).ToString))
Next

'function to test printer status
Private Function CheckPrinter(ByVal printerName As String) As Boolean
    Try
        Dim printDocument As PrintDocument = New PrintDocument
        printDocument.PrinterSettings.PrinterName = printerName
        Return printDocument.PrinterSettings.IsValid
    Catch ex As System.Exception
        Return False
    End Try
End Function

Upvotes: 3

Hyperboreus
Hyperboreus

Reputation: 32429

As you use Vb.net I guess you are on a windows machine. Use your operating systems API. Like e.g. GetPrinterStatus.

Upvotes: -1

Related Questions