HTA Makes Installing Shared Printers Easy

To install a printer with this HTA, all you need to do is specify the name you want to give the printer, provide the printer's IP address, and select the appropriate printer driver.

Dave Gest

September 10, 2006

3 Min Read
ITPro Today logo in a gray background | ITPro Today


I created an HTML Application(HTA) named Install_Printer thatmakes installing printers on aprint server easy and consistent. ThisHTA uses the Microsoft WindowsServer 2003 Resource Kit’s PrinterAdmin (prnadmin.dll) tool to create theprinter port, share the printer, publishit to Active Directory (AD), and recordthe printer information in the printer’sproperties page.

Here’s how Install_Printer works.When you double-click the HTA, theWindow_Onload subroutine runs.This subroutine checks to see whetherprnadmin.dll is present in three locations: C:Program FilesWindows Resource KitsTools, %SystemRoot%,and %SystemRoot%System32.

When prnadmin.dll isn’t present inany of these locations, the HTA callsthe ShowFile subroutine. This subroutine performs two tasks. First, itprompts the HTA UI to open with theprinter driver drop-down list and theCreate Shared Printer button disabled,as Figure 1 shows. Second, it promptsthe HTA UI to open with some elements designed to obtain the pathname to prnadmin.dll, as the bottomof Figure 1 shows. The user can provide a pathname to the DLL by entering it or by browsing to it. Note thatthe browse functionality is availableonly in Windows Server 2003 andWindows XP. After you provide a pathname and click the Continue button,the HTA copies prnadmin.dll to theSystem32 directory and uses theRegsvr32 command to register theDLL with the system. The HTA thenprompts the user to close and reopenthe HTA so that the printer driverdrop-down list and the Create SharedPrinter button are no longer disabled.

When prnadmin.dll is present, theHTA creates instances of three prnadmin.dll objects. The HTA then usesWindows Management Instrumentation’s (WMI’s) Win32_PrinterDriverclass to enumerate all the installedprint drivers on the local machine andpopulate the printer driver drop-down list. (Although you can use prnadmin.dll to enumerate printerdrivers, I had some problems using itfor this purpose.) The final result isthat the HTA UI opens with theoptions you need to install a printer,as Figure 2 shows.

To install a printer, you simplyneed to specify the name you want togive the printer, provide the printer’sIP address, and select the appropriateprinter driver. (If the driver you needisn’t in the list, you must install thedriver and run the HTA again to havethe driver appear.) Optionally, youcan include a comment about theprinter and specify the printer’s location. This information will appear inthe printer’s property page. Althoughit isn’t required to create the shared printer, it can be helpful, especiallywhen you manage many printers.Note that the HTA automatically addsthe printer’s IP address and name tothe beginning of the comment line inthe printer’s properties page, even ifyou don’t enter anything in the HTA’scomment text box.

When you click the Create SharedPrinter button, the HTA uses the specified IP address to create a standardTCP/IP port. The HTA then creates theprinter and sets several of its options,including disabling bidirectional communication, disabling SNMP, and setting the port to TCP raw and the portnumber to 9100. You can change theseand other settings. Prnadmin.dll hasnumerous properties, which you canread about in the resource kit’s Prnadmin.doc file.

The HTA creates a Web page toshow its progress. I often use this typeof progress reporting because an HTAcan’t show its progress while executinga script because it’s in a busy state.Having the HTA create a new windowlets the HTA post updates while it’sexecuting a script. You can downloadthe Install_Printer.hta from the Download the Code box at the top of the Web page.
—Dave Gest

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like