.AddPrinterConn - VBScript


Overview

The .AddPrinterConn command in VB Script establishes a connection to a printer or a print queue. It is commonly used in scripting environments to automate printing tasks, such as adding or removing printers, managing print jobs, and configuring print settings.

Syntax

.AddPrinterConn(Printer, [Connection], [Prompt])

Parameters:

  • Printer: Required. The name of the printer or print queue to connect to.
  • Connection: Optional. Specifies the connection string or UNC path for the network printer. If not provided, the default connection for the specified printer will be used.
  • Prompt: Optional. A Boolean value indicating whether to display a printer connection dialog. If True, the user will be prompted to provide connection details.

Options/Flags

There are no options or flags available for this command.

Examples

Simple Example:

Set objPrinter = CreateObject("WScript.Network")
objPrinter.AddPrinterConn "HP LaserJet 1018"

Example with UNC Path:

Set objPrinter = CreateObject("WScript.Network")
objPrinter.AddPrinterConn "NetworkPrinter", "\\server\share\printer"

Example with Prompt:

Set objPrinter = CreateObject("WScript.Network")
objPrinter.AddPrinterConn "NewPrinter", , True

Common Issues

Error: “Printer not found”
Resolution: Ensure that the specified printer name is correct and exists on the network or local system.

Error: “Access denied”
Resolution: Check if the user has sufficient permissions to add a printer connection.

Integration

The .AddPrinterConn command can be used in conjunction with other VB Script commands for advanced printing tasks. For instance, you can use .Printer.Print to send a document to the connected printer.

  • .Printer.Print: Prints a document to the specified printer.
  • .Printer.Properties: Gets or sets the properties of the connected printer.
  • .NetUse: Connects to a network resource, including printers.