Bahut

Thursday, February 23, 2006

Installing printers is terribly boring. As is often the case with Windows, it is possible to automate/script tasks like this, but it is usually complicated and awkward.

There is an arcane rundll32 command which can be used, preceded by some vbscript to create the TCP/IP ports for network printers.

Another possibility is a Microsoft tool that has to be downloaded separately, called Print Migrator. This is what I will try next. I tried this, and indeed, it makes it very easy to replicate printer settings to other machines in the same network. The drawback is that it saves and restores all printers. They cannot be selected individually. The advantage is that it works across operating systems, so it doesn't matter if the machines are Windows 2000, XP, or even NT4. And it couldn't be any easier to use.

For the complicated rundll32 version, an excellent page with many examples, is here. That's where I also found the link to Print Migrator. There may be much more good stuff on that site, but the terrible layout (it even uses frames!) discourages me at the moment, so I will just have to return there later...

To create the TCP/IP ports, I use a VBS script like this one, which takes an IP address as argument:

However, while this Perl script has worked on one machine, it has not on another. The GPD file was corrected, but there are also registry settings involved, and it sometimes just doesn't work.

After long searches to solve this problem, here is what I found: the paper size is stored in the registry, in a binary structure which is dependent on the printer driver. This means it cannot be edited directly in the registry. This driver structure is partly documented, and can be accessed through the Windows API, but not through VBScript and the WSH.

There is no easy way to change the default paper size!

The only workaround which I found is to use rundll32 again, to save and restore a specific printer's settings. The following command saves my LaserJet 5M settings to the file laserjet-5M-settings.dat: