Export (0) Print
Expand All

Adding a Printer Connection by Using WSH

Microsoft® Windows® 2000 Scripting Guide

The WSH AddWindowsPrinterConnection method provides a quick and easy way to add a printer connection to the local computer. (To add a printer connection to a remote computer, you will need to run the WSH script using the WSHController object.)

The AddWindowsPrinterConnection method requires only a single parameter: the UNC path to the network printer. For example, this line of code adds a connection to the printer named ColorPrinter managed by the print server atl-ps-001:



objNetwork.AddWindowsPrinterConnection "\\atl-ps-001\ColorPrinter"

After a printer connection has been created, you can optionally use the SetDefaultPrinter method to configure the new connection to be the default printer. SetDefaultPrinter also requires only one parameter: the UNC path to the network printer.

Scripting Steps

Listing 13.23 contains a script that adds a printer connection on the local computer. To carry out this task, the script must perform the following steps:

  1. Create an instance of the WSH Network object.

  2. Use the AddWindowsPrinterConnection method to add a connection to the printer Xerox300 on the print server atl-ps-01.

  3. Use the SetDefaultPrinter method to configure the printer Xerox300 on the print server atl-ps-01 as the default printer.

Listing 13.23 Adding a Printer Connection

  
1
2
3


Set objNetwork = CreateObject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection "\\atl-ps-01\Xerox300"
objNetwork.SetDefaultPrinter "\\atl-ps-01\Xerox300"

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft