Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


September 11, 2006

HTA Makes Installing Shared Printers Easy

RSS
Subscribe to Windows IT Pro | See More Printing Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Task Automation Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Will Your Next Generation Server System Meet Your Infrastructure Optimization Needs?

Continuous Data Protection and Recovery for Microsoft Exchange

Related Events WinConnections and Microsoft® Exchange Connections

Managing IT Across Multiple Locations

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement