AddPrinterConnection method of the Win32_Printer class

The AddPrinterConnection WMI class method provides a connection to an existing printer on the network, and adds it to the list of available printers.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 AddPrinterConnection(
  [in] string Name
);

Parameters

Name [in]

Friendly name for the printer.

Return value

Returns one of the values listed in the following list, or any other value to indicate an error. For additional error codes, see WMI Error Constants or WbemErrorEnum. For general HRESULT values, see System Error Codes.

0

Success

5

Access Denied

1801

Invalid Printer Name

1930

Incompatible Printer Driver

Examples

The following VBScript code sample adds a local printer.

Dim strPrinterName as String = "Isidoros Printer"
Dim strComputer AsString = My.Computer.Name
Dim objWMIService, objPrinter AsObject
objWMIService = GetObject(
"winmgmts:" _

& 
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objPrinter = objWMIService.Get(
"Win32_Printer").SpawnInstance_
objPrinter.Name = strPrinterName
objPrinter.DriverName = "Generic / Text Only"
objPrinter.PortName = 
"c:\temp\file.prn"
objPrinter.DeviceID = strPrinterName
'objPrinter.Location = "Athens, Greece"
objPrinter.Network = 
False
objPrinter.Shared = 
False'objPrinter.ShareName = "MyShareName"
objPrinter.Put_()

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\CIMV2
MOF
Win32_Printer.mof
DLL
CIMWin32.dll

See also

Computer System Hardware Classes

WMI Tasks: Printers and Printing

Win32_Printer