Compartir a través de


Controlling Networked Printers

The Network object enables you to access printing devices on your network. The following scripts demonstrate the use of the Network object to control a network printer device.

Connecting to a Remote Printer

The following scripts demonstrate how to connect to a network shared printing device. In the first step, the script creates a Network Object. Next, the AddWindowsPrinterConnection method, one of the Network object's methods, performs the connection operation. The AddWindowsPrinterConnection method takes two parameters: the name you wish to call the printer and the Universal Naming Convention (UNC) path to the printing device.

// JScript.
var net;
net = new ActiveXObject("WScript.Network");
net.AddWindowsPrinterConnection("\\\\ServerName\\PrinterName");

' VBScript.
Dim net
Set net = CreateObject("WScript.Network")    
net.AddWindowsPrinterConnection "\\ServerName\PrinterName"

Setting Default Printer

The following script demonstrates how to set the desired default printing device. In the first step, the script creates a Network Object. Next, the SetDefaultPrinter method, one of the Network object's methods, performs the operation. The SetDefaultPrinter method takes a single parameter, the name of the printer, which is either the local printer name or a remote printer name using the Universal Naming Convention (UNC) path to the printing device.

// JScript.
var net;
net = new ActiveXObject("WScript.Network");
net.SetDefaultPrinter("\\\\ServerName\\PrinterName");

' VBScript.
Dim net
Set net = CreateObject("WScript.Network")    
net.SetDefaultPrinter "\\ServerName\PrinterName"

See Also

Reference

AddWindowsPrinterConnection Method

SetDefaultPrinter Method

RemovePrinterConnection Method

Other Resources

Accessing Networks