Adding a Printer Connection by Using WSH

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

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"

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net