Hello,

I had a script to install and remove network printer, but it does not work anyone.

Dim wshNetwork
Set wshNetwork = CreateObject("WScript.Network")

wshNetwork.AddWindowsPrinterConnection "\\admcprint1\AGRicohC4503"

wshNetwork.SetDefaultPrinter "\\admcprint1\AGRicohC4503"

wshNetwork.RemovePrinterConnection "\\admcprint1\agricoh4002sp"
wshNetwork.RemovePrinterConnection "\\admcprint1\agricohmpc3002"


or is there an easier way to install a new network printer and remove the old one.

1 Comment   [ + ] Show Comment

Comments

  • I think I might have solved it. I needed to run as the user not local system on the script settings.
Please log in to comment

Answers

1
You looking for help or just wanting to knock people down?
Answered 03/31/2016 by: alphabeta
Fifth Degree Brown Belt

Please log in to comment
1
' Variables must be declared
Option Explicit
' Suppress errors
on error resume next
' Declare Variables
Dim objPrinter, printerPath
' Path to printer (Add your information below)
printerPath = "\\dr-acad\red-204"
Set objPrinter = CreateObject("WScript.Network")
' Add printer
objPrinter.AddWindowsPrinterConnection printerPath
' Add as default
objPrinter.SetDefaultPrinter printerPath
wscript.sleep 200
' Path to printer (Add your information below)
printerPath = "\\dr-acad\red-204-single-sided"
Set objPrinter = CreateObject("WScript.Network")
' Add printer
objPrinter.AddWindowsPrinterConnection printerPath
wscript.sleep 200
WScript.Quit

Answered 03/31/2016 by: SMal.tmcc
Red Belt

Please log in to comment
0
Try this following VBS script. First half should remove any and all network printers attached without needing to specify a name. Second half should attach the printers you need. Obviously replicate the add printer line if you've more than one printer.


on error resume next

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery ("Select * from Win32_Printer where Network = TRUE")

For Each objPrinter in colInstalledPrinters
    'wscript.echo objPrinter.name
    objPrinter.Delete_
Next





Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.AddWindowsPrinterConnection "\\ServerName\PrinterName"
WshNetwork.SetDefaultPrinter "\\ServerName\PrinterName"

Set WshNetwork = nothing
Answered 03/31/2016 by: alphabeta
Fifth Degree Brown Belt

Please log in to comment
0
Jeez! Why reinvent the wheel? Microsoft provide a bunch of scripts that will do pretty much anything to do with printers, ports, etc: Prncnfg.vbs, Prndrvr.vbs, Prnjobs.vbs, Prnmngr.vbs, Prnport.vbs, Prnqctl.vbs should be located in %windir%\System32\Printing_Admin_Scripts\en-US
Answered 03/31/2016 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity