RemovePrinterConnection Method 

Removes a shared network printer connection from your computer system.


object.RemovePrinterConnection(strName, [bForce], [bUpdateProfile])

Arguments

  • object
    WshNetwork object.
  • strName
    String value indicating the name that identifies the printer. It can be a UNC name (in the form \\xxx\yyy) or a local name (such as LPT1).
  • bForce
    Optional. Boolean value indicating whether to force the removal of the mapped printer. If set to true (the default is false), the printer connection is removed whether or not a user is connected.
  • bUpdateProfile
    Optional. Boolean value. If set to true (the default is false), the change is saved in the user's profile.

Remarks

The RemovePrinterConnection method removes both Windows and MS-DOS based printer connections. If the printer was connected using the method AddPrinterConnection, strName must be the printer's local name. If the printer was connected using the AddWindowsPrinterConnection method or was added manually (using the Add Printer wizard), then strName must be the printer's UNC name.

Example

The following code disconnects a network printer.

Set WshNetwork = WScript.CreateObject("WScript.Network")

PrinterPath = "\\printserv\DefaultPrinter"

WshNetwork.RemovePrinterConnection PrinterPath, true, true
var WshNetwork = WScript.CreateObject("WScript.Network");

var PrinterPath = "\\\\PRN-CORP1\\B41-4523-A";

WshNetwork.RemovePrinterConnection(PrinterPath, true, true);

Applies To:

WshNetwork Object

See Also

Reference

AddPrinterConnection Method
AddWindowsPrinterConnection Method
EnumPrinterConnections Method
SetDefaultPrinter Method