• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

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.
0
skymag
Asked:
skymag
  • 2
1 Solution
 
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
 
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now