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

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.


I don't think this is possible.

As you already found out this is abstracted using the spooler and the spooler status doesn't always reflect the printer status.

So this is by design in Windows.

If you only have one specific printer type you could query if it is attached to USB.

链接地址: http://www.djcxy.com/p/56270.html

上一篇: C#中的使用示例

下一篇: 如何检测连接的USB打印机是打开还是关闭?