Link to home
Start Free TrialLog in
Avatar of greendot
greendot

asked on

Detecting if network printer has been removed

Is there a way to detect if a network printer has been removed?

What's happening in our app is that various client machines all point to a central network printer.  When that printer is removed, all clients still point to it... and when we try to print to that printer, we get exceptions generated.

Dealing with the exceptions isn't a problem, but we would like to figure out a way to detect the situation before we start to print.  (There is a lot of overhead in page generation before the exceptions are raised.)

Any clues?

thanks
greendot
Avatar of KE
KE

Why not branch on an exception in the first stage - before generating the page ?

Does the exception only occur when you output ???

Regards
Perhaps enumerating the network resources with WNetOpenEnum helps?

Regards, Madshi.
If you use TCP/IP to network print (like LPR), you can try to ping the printer first.  No ping - no printer.
Avatar of greendot

ASKER

In house, we use TCP/IP, but the customer base is supposed to be able to use any windows based networking - i.e. invisible to us.

I'm going to try that WNetOpenEnum thing and see if it works.

-j
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Madshi, that code example you pointed me to worked perfectly.  All I had to do was remove the good parts and turn it into a function that dealt with only printer resources.

thanks.

-gd
FYI, it turns out that a simple call to OpenPrinter (winspool.pas) will return false in the case that the printer is no longer attached to the server.

I'm going to see if that one passes tests on all Win32 platforms.

-gd
Please keep us informed about the results of your tests - thank you!!   :-)
Well, OpenPrinter works perfectly on my development machine.  It fails and passes on the correct printers.  

But, I move to a friends machine and it doesn't work.

The enumeration code example still works...
Okay, thanx for the info...  
:-)