script will not work
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
-
I think I might have solved it. I needed to run as the user not local system on the script settings. - Kdebiasse 8 years ago
Answers (4)
Please log in to answer
Posted by:
SMal.tmcc
8 years ago
' 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
Posted by:
alphabeta
8 years ago
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
Posted by:
anonymous_9363
8 years ago