Click to Rate and Give Feedback
MSDN
MSDN Library
Collapse All/Expand All Collapse All
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
Windows Script Host
AddWindowsPrinterConnection Method

Adds a Windows-based printer connection to your computer system.

Windows NT/2000:
object.AddWindowsPrinterConnection(
   strPrinterPath
)
Windows 9x/Me:
object.AddWindowsPrinterConnection(
   strPrinterPath,
   strDriverName[,strPort]
)
object

WshNetwork object.

strPrinterPath

String value indicating the path to the printer connection.

strDriverName

String value indicating the name of the driver (ignored if used on Windows NT/Windows 2000).

strPort

Optional. String value specifying a printer port for the printer connection (ignored on Windows NT/Windows 2000).

Using this method is similar to using the Printer option on Control Panel to add a printer connection. Unlike the AddPrinterConnection method, this method allows you to create a printer connection without directing it to a specific port, such as LPT1. If the connection fails, an error is thrown. In Windows 9x/Me, the printer driver must already be installed on the machine for the AddWindowsPrinterConnection method to work. If the driver is not installed, Windows returns an error message.

The following code uses the AddWindowsPrinterConnection method to connect a network printer to a Windows NT/2000 computer system.

VBScript
Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\printserv\DefaultPrinter"
WshNetwork.AddWindowsPrinterConnection PrinterPath
JScript
var WshNetwork = WScript.CreateObject("WScript.Network");
var PrinterPath = "\\\\printserv\\DefaultPrinter";
WshNetwork.AddWindowsPrinterConnection(PrinterPath);

The following code uses the AddWindowsPrinterConnection method to connect a network printer to a Windows 9x/Me computer system.

VBScript
Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\printserv\DefaultPrinter"
PrinterDriver = "Lexmark Optra S 1650"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
JScript
var WshNetwork = WScript.CreateObject("WScript.Network");
var PrinterPath = "\\\\printserv\\DefaultPrinter";
var PrinterDriver = "Lexmark Optra S 1650";
WshNetwork.AddWindowsPrinterConnection(PrinterPath, PrinterDriver);

Applies To:

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker