You are currently offline, waiting for your internet to reconnect

HOW TO: Programmatically Create a Printer and Printer Port by Using PrinterAdmin (Prnadmin.dll) with a Visual Basic Script in Microsoft Windows 2000

This article was previously published under Q321025
This article applies to Windows 2000. Support for Windows 2000 ends on July 13, 2010. The Windows 2000 End-of-Support Solution Center is a starting point for planning your migration strategy from Windows 2000. For more information see the Microsoft Support Lifecycle Policy.
This article has been archived. It is offered "as is" and will no longer be updated.
This step-by-step article describes how to programmatically create a printer and printer port by using the PrinterAdmin tool (Prnadmin.dll) and a Visual Basic script in Microsoft Windows 2000.

back to the top

Overview of Prnadmin.dll

PrinterAdmin is available in the Microsoft Windows 2000 Resource Kit. It is a Component Object Model (COM)-based tool that administrators can use to manage printers, drivers, and ports on local and remote Windows 2000-based computers. PrinterAdmin provides large-scale, non-interactive control of printers through the use of scripts. You can either create your own scripts or modify one of the sample scripts that is provided with PrinterAdmin to perform the following tasks:
  • Add and delete a printer.
  • Add and delete a printer driver.
  • Add and delete a printer port.
  • Add and delete a form.
  • View a list of printers, ports, drivers, and forms on a specific computer.
  • Control and configure printers.
  • Print a test page.
  • Clone a print server.
The example Visual Basic script in this article demonstrates how to use Prnadmin.dll to remotely add a printer and printer port on Windows 2000-based computers. The script performs the following tasks:
  • Creates a new port on the client computer. In this example, the port points to the C:\MyFolder\MyPort folder on the computer's hard disk.
  • Installs a printer that uses the new port on the client computer.
  • Creates a C:\MyFolder folder on the client computer's hard disk (in which to store documents that are sent to the new printer).
back to the top

How to Add a Printer and Printer Port by Using Prnadmin.dll with a Visual Basic Script

  1. Start Notepad, and then open a new text file.
  2. Copy and paste the following lines into the text file:

    NOTE: To use Prnadmin.dll, it must be registered on the client computer. The script registers Prnadmin.dll from its location on the server. Make sure that you change \\Servername\Foldername to the correct path to the Prnadmin.dll file on your server.
    '******** Register prnadmin.dll file on client computer *******Set WshShell = Wscript.CreateObject("Wscript.Shell")WshShell.Run "regsvr32 /s \\ServerName\FolderName\Prnadmin.dll",1,TRUE'************** Create the port first *******************************dim oPortdim oMasterset oPort = CreateObject("Port.Port.1")set oMaster = CreateObject("PrintMaster.PrintMaster.1")oPort.PortName = "C:\MyFolder\MyPort"oPort.PortType = 3oMaster.PortAdd oPortif Err <> 0 thenmsgbox "There was an error creating the port."end if'********************************************************************'************** Create the printer second ***************************'Change MyPrinter to the name of the printer that you are adding.'Change PrinterDriver to the name of the printer driver that you are adding.dim oPrinterset oPrinter = CreateObject("Printer.Printer.1")oPrinter.PrinterName = "MyPrinter"		' name of the printer as it appears in the Printers folderoPrinter.DriverName = "PrinterDriver"		' name that is referenced in ntprint.infoPrinter.PortName = "C:\MyFolder\MyPort"		' Specify a port name. Can also point to LPT or COM port.oMaster.PrinterAdd oPrinterIf Err <> 0 thenmsgbox "There was an error creating the printer."end if'********************************************************************'************** Create the directory third ***************************Dim filesysSet filesys = wscript.createobject("Scripting.FilesystemObject")filesys.CreateFolder "C:\MyFolder\"			' Create a folder as a repository for the faxes.If Err <> 0 thenmsgbox "There was an error creating the MyFolder folder."end if'********************************************************************msgbox "The script is finished."					
  3. Customize the script (as necessary) to meet your requirements.
  4. On the File menu, click Save As. Type a name for the script in the File name box by using the .vbs file name extension (for example, MyPrinter.vbs), specify a location where you want to save the file, and then click Save.

    NOTE: Make sure that you include the quotation marks ("") when you type the file name. This action creates the file with the .vbs file name extension.
  5. Quit Notepad.
  6. Deploy the script to users' computers.

    When the script is run, a new port is created, the printer is installed, and the printer appears in the Printers folder of the client computer.
back to the top

For more information about the PrinterAdmin tool, see the Prnadmin.doc file that is available in the Windows 2000 Resource Kit. The Prnadmin.doc file is located in the Program Files\Resource Kit folder (if the Windows 2000 Resource Kit is installed to the default location).

For more information about the Windows 2000 Resource Kit, visit the following Microsoft Web site: For additional information about how to add a default printer by using a Visual Basic script, click the article number below to view the article in the Microsoft Knowledge Base:
263226 How to Add a Default Printer Using a Visual Basic Script
For additional information about how to migrate a print server configuration between Windows NT 4.0 and Windows 2000 computers, click the article number below to view the article in the Microsoft Knowledge Base:
315983 HOW TO: Migrate a Printer Server Configuration Between Windows NT 4.0 or Windows 2000 Computers with the Printer Migrator 2000 Tool
back to the top

Article ID: 321025 - Last Review: 12/07/2015 10:35:46 - Revision: 5.5

Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server, Microsoft Windows 2000 Professional Edition

  • kbnosurvey kbarchive kbhowto kbhowtomaster KB321025