PDA

View Full Version : Detect any installed printers


boku
03-23-2009, 01:21 AM
I have been using another thread solution to detect a printer, which works great ... except if there is no printer installed!

The Other Post (http://www.indigorose.com/forums/showpost.php?p=93459&postcount=2)

...............

How would I handle the error if no printer is installed?

Getting quite frustrated, can I even suppress the error?

Any help please... All i need to do is detect whether or not a printer is installed, but I get "a nil value" if no printer is found.

Dermot
03-23-2009, 02:00 AM
result = Registry.GetKeyNames(HKEY_LOCAL_MACHINE, "\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers");

if result then
Dialog.Message("Notice", result[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end

boku
03-23-2009, 02:03 AM
Yes that's the code I'm already using. But it shows an application error IF there is NO printer at that location in the registry, which I CANNOT seem to remove.

But thank you for your reply

mwreyf1
03-23-2009, 07:41 AM
The code that Dermot posted would NOT return an error.

If you are receiving an error it is somewhere else in your code.

lnd
03-23-2009, 10:07 AM
how can i know if the printer is a default or not??? and if the printer is in offline???

boku
03-23-2009, 07:01 PM
The code that Dermot posted would NOT return an error.

If you are receiving an error it is somewhere else in your code.

Had to go back through my code and compare it to Dermots. I removed the [1] and got it to work perfectly.

For everyone else i can confirm that this code works on XP for sure.


PrinterExists = Registry.GetKeyNames(HKEY_LOCAL_MACHINE, "\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers");

if PrinterExists then
Button.SetVisible("btnNext3", true);
else;
Button.SetVisible("btnNext3", false);
end