Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

September 11, 2006 12:00 AM

HTA Makes Installing Shared Printers Easy

Windows IT Pro
InstantDoc ID #93233
Rating: (1)
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

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.