Add Printers Script

From TrialWorks Wiki
Jump to: navigation, search


This script, in vbs form, will allow you automatically install network printers on all computers.


This method involves creating a VBS script and adding it to group policy or logon script.


Create a file called "printers.vbs" in your GPO folder or SYSVOL and add it to your logon script.

Option Explicit
Dim multiPrinter, UNCpath1, UNCpath2, UNCpath3, UNCpath4, UNCpath5
UNCpath1 = "\\server\Sharp550"
UNCpath2 = "\\server\Ricoh3500"
UNCpath3 = "\\server\RICOH2238"
UNCpath4 = "\\server\HP2200DN"
UNCpath5 = "\\server\Dell5210"
Set multiPrinter = CreateObject("WScript.Network") 
multiPrinter.AddWindowsPrinterConnection UNCpath1
multiPrinter.AddWindowsPrinterConnection UNCpath2
multiPrinter.AddWindowsPrinterConnection UNCpath3
multiPrinter.AddWindowsPrinterConnection UNCpath4
multiPrinter.AddWindowsPrinterConnection UNCpath5
' End of Script
    Alternative method
Option Explicit
Dim objWshShell
Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.Run "rundll32 printui.dll,PrintUIEntry /in /Gw /q /n ""\\SBS2011\SHARPCopier""",1, true
Option Explicit
Dim objWMIService, objPrinter, colItems, strComputer, objWshShell, strDefaultState
strComputer ="."
' --------------------------------------------
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' For Remote:
' Set Locator = CreateObject("WbemScripting.SWbemLocator") 
' Set objWMIService = Locator.ConnectServer(strComputer, "root\cimv2", strUserName, strPassword) 
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
' On Error Resume Next
For Each objPrinter In colItems
' Each IF block below is a printer replacement
If UCase(objPrinter.DeviceID) = UCase("\\KAREN\magicolor 2300 DL") Then
   ' Wscript.Echo "Found match " & objPrinter.DeviceID & ", replacing"
   ' Add new printer. Need the ,1,true to wait for shell to complete before continue
   objWshShell.Run "rundll32 printui.dll,PrintUIEntry /in /Gw /q /n ""\\T-101\magicolor 2300 DL""",1, true
   ' Remove the old
   objWshShell.Run "rundll32 printui.dll,PrintUIEntry /dn /q /n ""\\KAREN\magicolor 2300 DL""",1, true
   If objPrinter.Default Then ' if it's the default set as default
      objWshShell.Run "rundll32 printui.dll,PrintUIEntry /y /n ""\\T-101\magicolor 2300 DL""",1, true
   End If
End If 

Group Policy or Logon Script

Take the file you created and add it to your logon script / GP.


When users logon the script will be triggered and it will connect all network printers. You may be prompted to OK the driver installation on the clients.