473,657 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fun with printers

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
Jan 20 '07 #1
4 5082
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
"Frank Rizzo" <no**@none.comw rote in message
news:uP******** ******@TK2MSFTN GP06.phx.gbl...
>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

Jan 20 '07 #2
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 OnQueryPrintSet tings method.

2. Create a new class derived from StandardPrintCo ntroller 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...y=PrintPreview
Dialog+and+Win3 2Exception+%22T he+RPC+server+i s+unavailab+PRS oCo%40newsgroup s
.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/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====

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

Jan 22 '07 #3
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

Jan 25 '07 #4
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

Jan 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5889
by: Aaron_TekRecycle.com | last post by:
Someone must have done this before?!? I have VBS code that will Enumerate all the Printers in the AD and Add the Printer Connection to the client... I'm just not a web developer so I need some example code or hand-holding on the web integration portion. Anyone? "Aaron_TekRecycle.com" <aaron_NAME@DOMAIN_tekrecycle.com> wrote in message
0
1578
by: Simon Thompson | last post by:
Hi, I have a VB6 ActiveX DLL that we use for printing. It iterates through the printers collection to set the printer to the one the user requested. This is called from ASP (VB Script) pages, and from a VB Web Class application. The problem is, sometimes the printers collection is empty, so it fails to print. The COM+ package is configured to run as a known user. This user has printers configured. If we logon to the Web Server as the...
1
1484
by: Vanessa | last post by:
Hi, I'm trying to loop through all the printers in my computer system using WMI. However, I found out that it doesn't really get the correct number of printers in my system. I have 16 printers in my printers & faxes. However, when I use the WMI to retrieve the printers in my system, it only retrieve 13 printers instead of 16.
1
2873
by: TheThrill | last post by:
I've got a report, Report1 that i want to print to network Printers A, B, C all with one key stroke. How do i do this?
7
9069
by: trint | last post by:
How can I add all the network printers to a combobox? Thanks, Trint
2
6218
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.) The printers installed on the web server under the account used by asp.net for this web application are network printers that are shared by other computers that are on our domain. Permission has been granted for everyone to print to them. The...
5
6675
by: lmttag | last post by:
ASP.NET 2.0 (C#) application Intranet application (not on the Internet) Using Windows authentication and impersonation Windows Server 2003 (IIS6) Server is a member server on a domain Logged into server as a domain user that is in the local Administrators group on the server Workstation is on the same domain Logged into the workstation as a domain user, which is also in the local Administrators group on the server and workstation
0
1577
by: Ravigwipro | last post by:
Hi, I m able to get the printers object to know what are the printers had been installed and all. here my requirement is i have to write a data from VB to MS Word. for the page setup i have to get printer info. problem here i m facing is , i m getting the printer info and am able to write the complete document in that case it is working fine..but while generation of document if it gets fail due to some runtime error, in the immediate run...
0
1219
by: Peter Duniho | last post by:
On Wed, 23 Apr 2008 09:40:14 -0700, Al Meadows <fineware@fineware.com> wrote: This doesn't really seem to be a .NET or C# question. However, you may want to look at the driver settings (printer properties). Usually when what you're describing happens, it's because the printer driver is substituting fonts that aren't built into the printer. It's more efficient for the driver to use font substitution, because then
4
5264
by: Frank Rizzo | last post by:
I basically need a list of printers that's returned by the Find Printers dialog ( http://www.sqleffects.com/mystuff/findPrinters.png ). I've tried the path of DirectoryEntry entry = new DirectoryEntry(strPath); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = "(objectCategory=printer)" foreach(SearchResult result in mySearcher.FindAll()) { strName = result.GetDirectoryEntry().Name;
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.