Have you got an idea on how to turn IP addresses to printer names in Windows 2000/XP ?
Is there some documentation about that ?
Sorry, I don’t know how to do that. Maybe some other list member can help?
– CMcP
The “PrinterName” that SetPrinterName uses would be the same name you’ll see if you go to Start/Settings/Printers and Faxes. To match those names with IP addresses, you’d need to get the “Port” information for each printer (I’m sure there’s a call for that in the win32all module, but I don’t know it) and you’d have to hope that the Port name follows the default convention of “IP_XXX.XXX.XXX.XXX” - I don’t know about anybody else, but I usually change the default port name to something more meaningful. Then you’d need to match the two lists and cross your fingers.
I’m going to go out on a limb here and say that you probably can’t do (exactly) that programmatically. But you can fake it.
Let me say in advance that I’ve never tried to do this through Python, but I’ve been doing it for years through batch files. I just Googled the “win32net” module, which provides an API to do what I’m about to describe - but if worst comes to worst, you can just sys.exec() or os.popen() some DOS command lines…
Since you’re in a Windows environment, I’m going to assume that all of your network printers can be accessed via UNC paths. If not - if you’ve been using the “UNIX Print Services” to access them - then you’ll need to find another way. If they are accessible via UNC, then
you should be able to type the following at a prompt:
net view \192.168.0.11 # where 192.168.0.11 is the IP address of your first printer
and see the name(s) of the print queue(s) being shared. Now you can use the “net use” command to attach a local port to that queue.
Before starting, create a new printer on each machine (if your network printers are lasers, I heartily recommend using either the HP Laserjet 4 driver, or the HP Laserjet Series II for really ancient printers. Those drivers are old and bulletproof.) When asked which port the printer is attached to, specify any unused LPT port - I’ll use LPT3.
With that preparation taken care of, here’s the routine:
(in Python) - SetPrinterName(‘HP LaserJet 4’)
(in DOS) NET USE LPT3: /delete /yes # disconnect LPT3 in case it wasn’t done last time
(in DOS) NET USE LPT3: \192.168.0.11\BINARY_P1 # or whatever the print queue name is
(in Python) print your first job - lots of handwaving here
(in DOS) NET USE LPT3: /delete /yes # disconnect LPT3, ready for next use
(in DOS) NET USE LPT3: \192.168.0.12\BINARY_P1 # or whatever…
(in Python) print your second job
(in DOS) NET USE LPT3: /delete /yes # disconnect LPT3, ready for next use
(in DOS) NET USE LPT3: \192.168.0.13\BINARY_P1 # you get the drill
(in Python) print your third job
(in DOS) NET USE LPT3: /delete /yes # leave things clean for next time
Hope that helps…
···
On Sun, Jul 13, 2008 at 2:59 PM, Colin McPhail colin.mcphail@talktalk.net wrote:
On 13 Jul 2008, at 19:57, Gesuato Emanuele wrote: