You are currently offline, waiting for your internet to reconnect

How to Add a Default Printer Using a Visual Basic Script

This article was previously published under Q263226
Notice
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.
SUMMARY
This article shows you how to use a Visual Basic script to add a printer and make it the default printer.
MORE INFORMATION
The Windows Printer Mapping on Terminal Service cannot automatically map a printer if the printer is not locally attached to an LPT, COM, or USB port.

To map network printers for use in Windows 2000 Terminal Services and Windows NT 4.0 Terminal Server, follow these steps:
  1. In the following script, replace PrinterDriver with the name of the driver you are adding and \\Server\Printer with the name of the shared printer and server:
    Set WshNetwork = CreateObject("WScript.Network")PrinterPath = "\\Server\Printer"PrinterDriver = "PrinterDriver"WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriverWshNetwork.SetDefaultPrinter "\\Server\Printer" 					
  2. Save and execute the script in a Visual Basic (VBS) file.
NOTE: The parameter PrinterDriver must have the exact name of the driver as it appears in the left column of the Ntprint.inf file.

For example, if you want to install a Cannon Bubble-Jet BJ-230, then the line in the script should read PrinterDriver = "Canon Bubble-Jet BJ-230".

Excerpt from ntprint.inf:
++++++++++++++++++"Canon Bubble-Jet BJ-230"  = CNBJ230.GPD, CanonCanon_Bubble-JeFF70,Canon_Bubble-Jet_BJ-230				
NOTE: Windows NT 4.0 Terminal Server does not have Windows Scripting Host by default. Windows Scripting Host must be installed first to execute the scripts.

To add a different printer for each user that logs on to Terminal Services, follow these steps:
  1. In the following script, replace PrinterDriver with the names of the drivers you are adding. Replace UsernameX with the name of the user, and add more sections as needed:
    Set WshNetwork = CreateObject("WScript.Network")Select Case WshNetWork.UserName     Case "Username1"            PrinterPath = "\\Server\Printer1"        PrinterDriver = "PrinterDriver"        WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver        WshNetwork.SetDefaultPrinter "\\Server\Printer1"        Case "Username2"            PrinterPath = "\\Server\Printer2"        PrinterDriver = "PrinterDriver"        WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver        WshNetwork.SetDefaultPrinter "\\Server\Printer1"End Select 					
  2. Set the script to run each time the user logs on to Terminal Services (use Logon Script or Group Policy) and end select.
REFERENCES
For more information about scripts, visit the following Microsoft Web site:
Terminal Services, add printer, network printer.
Properties

Article ID: 263226 - Last Review: 03/27/2007 01:33:21 - Revision: 5.6

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional Edition
  • Microsoft Windows 2000 Datacenter Server
  • Microsoft Windows NT Server 3.51
  • Microsoft Windows NT Workstation 4.0 Developer Edition
  • kbconversion kbdynamic kbhowto KB263226
Feedback