Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a connected USB printer is on or off?

I want to detect if a printer is Online/offline BEFORE attempting to print. If it is offline - the print dialog will not be Visible.

The Win32 API's "OpenPrinter" etc. seem to work on the spooler queue, rather than the printer itself, and will only report the printer offline AFTER a document is sent, whichis too late.

QUESTION: How can I tell if a printer is offline/online without sending a print out to it?

EDIT:

Offline - printer is turned off
OnLine  - printer is turned On
like image 764
Charles Faiga Avatar asked Nov 17 '11 12:11

Charles Faiga


People also ask

How do you check if the printer is on?

Your printer's built-in menu should show which network it's connected to, or check your printer's manual for more info. Verify that your printer is not in Use Printer Offline mode. Select Start > Settings > Devices > Printers & scanners. Then select your printer > Open queue.

How do I know if my USB printer is working?

Turn on the printer and try printing a page. If this doesn't work, shut down the computer, and then try using a different port on the computer. If this still doesn't work, reverse the cable and try one more time to eliminate a faulty cable or connection as the problem.

How can I check if my printer is active?

Right-click on your printer to see a list of options. To view the print queue, select "See what's printing." To check general printer status, select "Properties," and to figure out if something is wrong with the printer select "Troubleshoot."


1 Answers

Presumably you know the name of the printer or other details about it.

Well, then simply use EnumPrinters with PRINTER_INFO_2 and check for PRINTER_STATUS_OFFLINE (or any other status that you want avoid).

Alternately you could try to use the SetupDi* functions (aka Setup API) to figure out whether the USB device matching the printer is connected at this very moment.

like image 146
0xC0000022L Avatar answered Oct 03 '22 00:10

0xC0000022L