Call Us For A Free Evaluation (509) 475-9070

HTA Makes Installing Printers Easy

HTA Makes Installing Printers Easy

HTA Makes Installing Printers Easy

       I’ve created a script to make installing printers on a print server easy and consistent using prnadmin.dll from the Windows Server 2003 Resource Kit and an HTA. The HTA relies on the prnadmin.dll file to create the printer port, share the printer, publish it to Active Directory, and set the name and comments of the printer properties.

      The script will check to see if the prnadmin.dll is present in three locations “C:\Program Files\Windows Resource Kits\Tools”, “%Systemroot%, and %Systemroot%\system32” if found the script will attempt to continue by making a reference to the objects as callout “A” shows. If an error occurs from the reference then it redirects to the “ShowFile” sub routine to get the prnadmin.dll and copy it to the system32 directory and register it with the system.


       If not found, two buttons and a textbox appears in the HTA giving you opportunity to specify a location to copy the file from. After the file is copied, it’s registered with the system using the “REGSVR32 prnadmin.dll” command. The script will prompt you to restart the HTA as the dropdown and “Create Shared Printer” buttons are disabled.


Once the HTA is started you will see four textbox’s, a dropdown list and one button as shown in Figure 1.  All that is needed is the share name you wish to give the printer, the IP address of the printer and to select the appropriate printer driver from the dropdown list. If the driver is not in the list then you must install the driver and run the HTA again to have the driver show up in the dropdown. The other two textbox’s are optional, as they refer to the comment and location of the printer’s properties and are not required to create the shared printer.


      The drop-down box is populated using the WMI and the Win32_PrinterDriver to enumerate all the print drivers installed on the server. Although you can use the Prnadmin.dll to enumerate printer drivers, I’ve had some issues consistently enumerating them from computer to computer in an HTA. In the HTA the user fills in the name of the printer to be installed, the IP address of the printer, then selects a printer driver from the drop-down list and makes any comments he wants to identify the printer.


      When the “Create Shared Printer” at the bottom of the page is clicked, the script creates a Standard TCP/IP port with the IP address the user provided and adds the printer’s IP address and name to the ports name to make it easy to find later. Then the script creates the printer and sets properties like disabling Bidirectional communication, disabling SNMP, and setting the port to “RAW” and the port number to “9100”. Step by step progress is reported by the creation of another web page a shown in Figure 2. I use this type of progress a lot because the starting HTA won’t show progress of a script while in execution as it is in a busy state, but having it create a new window allows the HTA to post updates to the new window while the script is executing.


      The only liabilities are that the script is dependent on the prnadmin.dll being registered with the system and that any printer you install with the script must have its driver installed on the system already. There is a operating system limitation if you are using an OS older that XP or server 2003 and that is the “Browse” button functionality if the prnadmin.dll file is not found. That function is only available with the XP and server 2003. Although the HTA provides a work around for older OS’s and that is the textbox and “Continue” button.


There is a “Help” link on the HTA that displays a web page showing most of the content of this article in it.



You can get the Windows Server Resource Kit here which also has a white paper on called prnadmin.doc


Sub Window_Onload

On Error Resume Next

            dir = Shell.ExpandEnvironmentStrings(“%Systemroot%\system32\prnadmin.dll”)

            dir2 = Shell.ExpandEnvironmentStrings(“%Systemroot%\prnadmin.dll”)

            dir3 = Shell.ExpandEnvironmentStrings(“%programfiles%\Windows Resource Kits\Tools\prnadmin.dll”)

              If FSO.FileExists(Dir) Or FSO.FileExists(Dir2) Or FSO.FileExists(Dir3)Then

 Callout        Set oPort = CreateObject(“Port.Port.1”)

        Set oMaster = CreateObject(“PrintMaster.PrintMaster.1”)

        set oPrinter = CreateObject(“Printer.Printer.1”)

        If Err Then ShowFile

        Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)

                        Set objWMIService = SWBemlocator.ConnectServer(net.ComputerName,”root\CIMV2″)

                        Set colItems = objWMIService.ExecQuery(“Select * from Win32_PrinterDriver”,,48)

                        For Each objItem in colItems

                     Set objOption = Document.createElement(“OPTION”)

                objOption.Text =Split(objItem.Name,”,”)(0)

                objOption.Value =Split(objItem.Name,”,”)(0)





              End If


End Sub

Fugure 1



Figure 2

            Set ProgressWindow = window.Open(“about:blank”,”Progress_Window”,”height=300,width=400,left=50,top=50,status=no,titlebar=no,SYSMENU=yes,toolbar=no,menubar=no,location=no,scrollbars=yes”)


   = “Tahoma”

   = “10pt”

            ProgressWindow.document.title = “Create Shared printer progress”

   = “none”

   = 15

Leave a Reply

Spokane Computer Repair and Networking (509) 475-9070