HOW TO: Programmatically Create a Printer and Printer Port by Using PrinterAdmin (Prnadmin.dll) with a Visual Basic Script in Microsoft Windows 2000 (321025)
The information in this article applies to:
- Microsoft Windows 2000 Server
- Microsoft Windows 2000 Advanced Server
- Microsoft Windows 2000 Professional
This article was previously published under Q321025 SUMMARY 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- Start Notepad, and then open a new text file.
- 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 oPort
dim oMaster
set oPort = CreateObject("Port.Port.1")
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
oPort.PortName = "C:\MyFolder\MyPort"
oPort.PortType = 3
oMaster.PortAdd oPort
if Err <> 0 then
msgbox "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 oPrinter
set oPrinter = CreateObject("Printer.Printer.1")
oPrinter.PrinterName = "MyPrinter" ' name of the printer as it appears in the Printers folder
oPrinter.DriverName = "PrinterDriver" ' name that is referenced in ntprint.inf
oPrinter.PortName = "C:\MyFolder\MyPort" ' Specify a port name. Can also point to LPT or COM port.
oMaster.PrinterAdd oPrinter
If Err <> 0 then
msgbox "There was an error creating the printer."
end if
'********************************************************************
'************** Create the directory third ***************************
Dim filesys
Set filesys = wscript.createobject("Scripting.FilesystemObject")
filesys.CreateFolder "C:\MyFolder\" ' Create a folder as a repository for the faxes.
If Err <> 0 then
msgbox "There was an error creating the MyFolder folder."
end if
'********************************************************************
msgbox "The script is finished."
- Customize the script (as necessary) to meet your
requirements.
- 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. - Quit Notepad.
- 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
REFERENCES 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
Modification Type: | Major | Last Reviewed: | 9/27/2006 |
---|
Keywords: | kbhowto kbHOWTOmaster KB321025 |
---|
|