PC Review


Reply
Thread Tools Rate Thread

How to detect if a printer is connected in C#?

 
 
=?Utf-8?B?WlM=?=
Guest
Posts: n/a
 
      6th Apr 2006
Hi,
in c# how can one detect if a printer is connected to the computer or not.
Thanks in advance
-zs
 
Reply With Quote
 
 
 
 
ssg31415926
Guest
Posts: n/a
 
      7th Apr 2006
Do you mean a locally attached printer or just a connection to a
network printer?

You could try using WMI (accessed via System.Management in .NET).
There's a Win32_Printer class which has a PrinterStatus field. I
gather that it doesn't work for every printer driver so you might have
to do some testing.

If you're new to WMI, get the WMI Tools (link at end) from MS. Use the
Object Browser to have a poke around.

You can get faster feedback knocking up the WMI part of your query in
script form and then converting to .NET. Go to ScriptCenter (link at
end) and get the WMI Scriptomatic. You can knock up WMI scripts and
test them very quickly and easily with this tool.

Also, this might help:
http://www.dotnet247.com/247referenc...45/229078.aspx

http://www.microsoft.com/downloads/d...5-F2ABDC3ED314
http://www.microsoft.com/technet/scr.../scripto2.mspx

 
Reply With Quote
 
 
 
 
=?Utf-8?B?WlM=?=
Guest
Posts: n/a
 
      7th Apr 2006
thanks for the response. I will try and let you know.


"ZS" wrote:

> Hi,
> in c# how can one detect if a printer is connected to the computer or not.
> Thanks in advance
> -zs

 
Reply With Quote
 
=?Utf-8?B?WlM=?=
Guest
Posts: n/a
 
      7th Apr 2006
I used the class System.Management.ManagementObjectSearcher class as follows :

System.Management.ManagementObjectSearcher searcher =
new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Printer");

the searcher.Get()returns printer objects even when not conneted to a
printer. It detectes all printers that are installed on my computer. and the
Printer status returns a value of Idle instead of Offline..
and when the user clicks on Print (when offline) it throws an exception. How
can I prevent this.

Can someone help me on this.
Thank you
-ZS





"ZS" wrote:

> Hi,
> in c# how can one detect if a printer is connected to the computer or not.
> Thanks in advance
> -zs

 
Reply With Quote
 
Radu Cosoveanu
Guest
Posts: n/a
 
      8th Apr 2006
To see if a printer is connected or not you should have bidirectional
communication between computer and printer. I think the best solution
could be to retreive the status of the printer from the driver status.
I think you cannot detect a lot of old printer if they are or not
online.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to detect printer is not connected to system hari Printers 7 10th Apr 2007 02:58 PM
Connected but not connected! =?Utf-8?B?Q2hyaXM=?= Windows XP Networking 1 1st Sep 2004 02:35 PM
Wireless Connection works from one USB connected pc but not the second USB connected pc alleykatzchic Windows XP Networking 0 10th Aug 2004 03:29 PM
Mapped Drive Not Connected but is Connected???? Fred Marshall Windows XP Networking 0 24th Jun 2004 04:10 PM
xp detect my usb connected printer bijo Windows XP Print / Fax 2 22nd Dec 2003 07:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:37 AM.