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
Anti-Virus Vendors Prepare for War with Microsoft ... Again

When Microsoft announced its Windows Live OneCare security and PC health product over five years (as MSN OneCare), Symantec, McAfee, and the other consumer-oriented security vendors reacted with stunning vigor. ...

What You Need to Know About Microsoft's x64 Server Product Plans

What do Longhorn Server, Windows Compute Cluster Server, and Windows Vista have in common? The x64 platform. ...

Command Prompt Tricks

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


Task Automation Whitepapers Business Innovation with Data Center Transformation

Batch Job Scheduling and .NET in 2008

Continuous Data Protection and Recovery for Microsoft Exchange

Related Events WinConnections and Microsoft® Exchange Connections

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 Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!


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 ITTV
IT Library Technology Resource Directory Connected Home asp.netPRO Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement | Reprints and Licensing