/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


script will not work

03/30/2016 1481 views

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.

All Answers

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

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

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
Black Belt

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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ