Other Scripts

Some BATCH and VBS scripts for various uses


Single printer change script

During a printer change over, i developed these scripts to change the installed printers on computers at startup. The process was the contactors installed the new printer, i setup the new printer queue and then we advised staff in that area to restart the computers. As the printers were setup per user, the new printer was installed at startup, saving a large number of calls to the Help Desk.

For a single printer

'Script deletes single printer and adds single printer
'Printer to be deleted is manually entered on line 7
'Printer to be added is manually enttered on line 13

Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\pr01\printer1" 

Set objNetwork = CreateObject("WScript.Network") 
On Error Resume Next
objNetwork.RemovePrinterConnection strUNCPrinter

strUNCPrinter = "\\pr01\printer1"
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.SetDefaultPrinter strUNCPrinter

For multiple printers

'Script deletes all network printers, then adds printer listed. Does not delete local printers or software printers (Adobe etc)
'Manually set printer name on line 13, 14, 15. Comment out lines if not required
'Set default printer on line 23 and 25

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

Dim multiPrinter, UNCpath1, UNCpath2, UNCpath3
UNCpath1 = "\\pr01\printer1"
UNCpath2 = "\\pr01\printer2"
'UNCpath3 = "\\pr01\printer3"
Set multiPrinter = CreateObject("WScript.Network")
multiPrinter.AddWindowsPrinterConnection UNCpath1
multiPrinter.AddWindowsPrinterConnection UNCpath2
'multiPrinter.AddWindowsPrinterConnection UNCpath3

Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\pr01\printer1"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WshNetwork.SetDefaultPrinter "\\pr01\printer1"
WScript.Quit