Checking for an attached printer

I need to check if there is a printer attached to the PC or not. I am using Windows NT 4 SP6. I would appreciate some sample code for Delphi 4 to detect a printer or not.
skymagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheNeilCommented:
Try accessing the Printers property of the Printer object. This will give you a list of the Printers attached (or that Windows is aware of), so if this list is empty then there aren't any printers actually attached (that Windows knows about)

E.g.
IF Printer.Printers.Count = 0
THEN
  MessageDlg('No printers known about', mtInformation, [mbOk], 0)
ELSE
  MessageDlg('Aware of ' + IntToStr(Printer.Printers.Count) + ' printers', mtInformation, [mbOk], 0);

The Neil
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MadshiCommented:
AFAIK there's no possibility to check whether a printer is really attached (and on power and ready for printing and ...).
The only thing you can do is look which printers are *installed* (that is what you find in ControlPanel->Printers). Use TheNeil's suggestion to do that.

Regards, Madshi.
0
TheNeilCommented:
If you send something to a printer that's not actually attached/powered up BUT is installed, then Windows will place it in the print queue anyway so it's not a problem. Madshi has confirmed what I thought (but didn't dare say in case I revealed that I am in fact an idiot) and Windows hides all that sort of thing from you

The Neil
0
skymagAuthor Commented:
Thanx this was exactly what I wanted. Luckily there will be no printer driver installed unless a printer is actually attached to the PC.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.