Skip navigation

HTA Makes Installing Shared Printers Easy

Downloads
93233.zip

I created an HTML Application (HTA) named Install_Printer that makes installing printers on a print server easy and consistent. This HTA uses the Microsoft Windows Server 2003 Resource Kit’s PrinterAdmin (prnadmin.dll) tool to create the printer port, share the printer, publish it to Active Directory (AD), and record the printer information in the printer’s properties page.

Here’s how Install_Printer works. When you double-click the HTA, the Window_Onload subroutine runs. This subroutine checks to see whether prnadmin.dll is present in three locations: C:\Program Files\Windows Resource Kits\Tools, %SystemRoot%, and %SystemRoot%\System32.

When prnadmin.dll isn’t present in any of these locations, the HTA calls the ShowFile subroutine. This subroutine performs two tasks. First, it prompts the HTA UI to open with the printer driver drop-down list and the Create Shared Printer button disabled, as Figure 1 shows. Second, it prompts the HTA UI to open with some elements designed to obtain the pathname to prnadmin.dll, as the bottom of Figure 1 shows. The user can provide a pathname to the DLL by entering it or by browsing to it. Note that the browse functionality is available only in Windows Server 2003 and Windows XP. After you provide a pathname and click the Continue button, the HTA copies prnadmin.dll to the System32 directory and uses the Regsvr32 command to register the DLL with the system. The HTA then prompts the user to close and reopen the HTA so that the printer driver drop-down list and the Create Shared Printer button are no longer disabled.

When prnadmin.dll is present, the HTA creates instances of three prnadmin.dll objects. The HTA then uses Windows Management Instrumentation’s (WMI’s) Win32_PrinterDriver class to enumerate all the installed print drivers on the local machine and populate the printer driver drop-down list. (Although you can use prnadmin.dll to enumerate printer drivers, I had some problems using it for this purpose.) The final result is that the HTA UI opens with the options you need to install a printer, as Figure 2 shows.

To install a printer, you simply need to specify the name you want to give the printer, provide the printer’s IP address, and select the appropriate printer driver. (If the driver you need isn’t in the list, you must install the driver and run the HTA again to have the driver appear.) Optionally, you can include a comment about the printer and specify the printer’s location. This information will appear in the printer’s property page. Although it isn’t required to create the shared printer, it can be helpful, especially when you manage many printers. Note that the HTA automatically adds the printer’s IP address and name to the beginning of the comment line in the printer’s properties page, even if you don’t enter anything in the HTA’s comment text box.

When you click the Create Shared Printer button, the HTA uses the specified IP address to create a standard TCP/IP port. The HTA then creates the printer and sets several of its options, including disabling bidirectional communication, disabling SNMP, and setting the port to TCP raw and the port number to 9100. You can change these and other settings. Prnadmin.dll has numerous properties, which you can read about in the resource kit’s Prnadmin.doc file.

The HTA creates a Web page to show its progress. I often use this type of progress reporting because an HTA can’t show its progress while executing a script because it’s in a busy state. Having the HTA create a new window lets the HTA post updates while it’s executing a script. You can download the Install_Printer.hta from the Download the Code box at the top of the Web page.
—Dave Gest

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish