Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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

Return codeDescription
0

Success

5

Access Denied

1801

Invalid Printer Name

1930

Incompatible Printer Driver

 

Examples

The Add-PrinterDriver PowerShell sample installs all printer drivers from a specified print server.

The ListSharedPrintersAddPrintConnection.ps1 PowerShell sample lists shared printers on a remote comptuer, and gives you the ability to add a printer connection from the remote computer to your computer.

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

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

Namespace

\root\CIMV2

MOF

CIMWin32.mof

DLL

CIMWin32.dll

See also

Computer System Hardware Classes
WMI Tasks: Printers and Printing
Win32_Printer

 

 

Show:
© 2014 Microsoft