You want to connect to a networked printer.
You can use the WScript.Network object's AddWindowsPrinterConnection method to connect to a networked Windows printer:
Dim objNetwork Set objNetwork = CreateObject("WScript.Network") objNetwork.AddWindowsPrinterConnection "\\odin\Brother HL-730"
The
AddWindowsPrinterConnection
method adds a networked printer to the local machine and was introduced in WSH 2.0. The syntax for the method is as
objNetwork.AddWindowsPrinterConnectionstrPrinterPath, [strDriverName] [,strPort]
Table 4-4 lists the parameters for the AddWindowsPrinterConnection method.
|
PARAMETER |
DESCRIPTION |
|---|---|
|
strPrinterPath |
|
|
strDriverName |
|
|
strPort |
Optional. Specifies the port to attach the printer to on Windows 95/98/ME. Default is LPT1. Ignored if used on Windows NT/2000 or XP platform. |
Using this method is the same as using the Control Panel Printers applet to add a printer connection. In Windows 95/98/ME, the printer driver must already be installed on the machine in order for the
AddWindowsPrinterConnection
method to work, which
Once you have added a printer, you may want to make it, or an existing printer, the default printer for your Windows applications. A default printer is automatically selected when you attempt to print from a Windows application. The syntax for the method is as follows:
objNetwork.SetDefaultPrinter(strPrinterPath)
The strPrinterPath parameter specifies the UNC path of the printer you want to make the default printer. The printer must be installed as a Windows printer appearing under the Control Panel Printer applet. The following code snippet sets the default printer to the network printer \\odin\brother :
Dim objNetwork Set objNetwork = CreateObject("WScript.Network") objNetwork.SetDefaultPrinter "\\odin\brother"
WSH has supported the addition of printers since the initial release using the AddPrinterConnection method. This method is useful only if you need to connect to printers from the command-line environment; the method is the equivalent of using the net use command. Printers that are connected using this method are not available from Windows applications.
The syntax for this method is as follows:
objNetwork. AddPrinterConnection strPort, strPrinterPath,[bUpdateProfile], [strUser], [strPassword]
Table 4-5 lists the parameters for the AddPrinterConnection method.
|
PARAMETER |
DESCRIPTION |
|---|---|
|
strPrinterPort |
The local printer port to connect the network printer to (e.g., LTP1:). |
|
strPrinterPath |
Path to the printer in UNC format (e.g., \\server\printername ). |
|
bUpdateProfile |
Optional Boolean parameter that determines if printer connection is stored in
|
|
strUserID |
Optional user ID for connecting to remote printer with. |
|
strPassword |
Optional password for connecting to remote printer. This is used in combination with the strUserID parameter. |
The following code snippet connects the LPT2 port to the remote printer laserjet on computer Odin:
Set objNetwork = CreateObject("Wscript.Network") objNetwork.AddPrinterConnection "LPT2", "\\odin\laserjet"