Fun with printers

F

Frank Rizzo

I have a USB printer connected to my PC. My winform app prints out some
text using the typical print methods that are normally used. I will
then turn off the printer or disconnect the USB cable. My application
still prints fine and reports no error. Of course, then windows pops up
a balloon from the system tray alerting me that the printing failed.
The print job just sits in the printer's print queue, until I reconnect
the printer and then it prints.

My questions is two fold:

1. How can I detect before printing whether the USB printer is connected?

2. How can I hook into the alert that Windows pops, so that my app
knows if the print failed? Of course, I just want alerts for the print
jobs I submit.

The interesting thing is that if I print to a network printer that is
disconnected, print methods do throw exceptions immediately.

Thanks
 
J

JR

It depends on the printer driver. If you look in the "Printers and Faxes"
window, you see "Ready". For some printers/drivers it changes when you turn
them off orr disconnect them, for others it does not.

The Windows API GetPrinter function gives you the same information. You can
also use the number of jobs in the queue - if it's too high the printer is
not working.

JR
 
L

Linda Liu [MSFT]

Hi Frank,

As for your two questions, I think we may need to make use of some Windows
APIs related to USB printer to get what you want. I have searched the
Internet for the Windows APIs, but unfortunately, I haven't found them yet.

I have ever handled a post before, which focused on how to catch
Win32Exception "The RPC server is unavailable" when a network printer is
disconnected. The steps of the workaround are like blow.

1. Create a new class derived from PrintDocument. Add a flag in the new
class and override the OnQueryPrintSettings method.

2. Create a new class derived from StandardPrintController and override
the OnStartPrint method.

3. When an error is raised in the overridden OnStartPrint method, set the
flag in the print document to true.

For more information on this post, you may visit the following link.

http://msdn.microsoft.com/newsgroups/managed/Default.aspx?query=PrintPreview
Dialog+and+Win32Exception+%22The+RPC+server+is+unavailab+PRSoCo%40newsgroups
.nospam

I am not sure whether the above workaround could solve your problem, but
give it a try please and let me know the result.

I will go on researching on your problems and will get it back to you ASAP.
I appreciate your patience.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Linda Liu [MSFT]

Hi Frank,

How about the problem now?

I have done more research on this problem.

The status of printers and print jobs are updated by the Win32 Spooler
during the despool of a print job. All other time, when that printer is not
despooling and resports no state information, the printer is considered to
be ready and idle. It means that if there's no print job in the print
queue, we have no way to get the real status of the physical printer.

To determine the state of a physical printer, there is one fundamental
premise that must be true: the Spooler must be attempting to send a print
job to the physical printer. This is the only time the state of the printer
is reported by the port monitor. In addition, the most meaningful
information may be reported in the status members of a JOB_INFO structure
for that particular print job because some port monitor will have set these
values directly.

For more information on how to get the status of a printer and a print job,
you may visit the following KB article.

'How to get the status of a printer and a print job'
http://support.microsoft.com/kb/160129/en-us

Hope this helps.
If you have any questions, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
L

Linda Liu [MSFT]

Hi Frank,

How about the problem now?

If the problem is not solved and you need our further assistance, please
feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!


Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top