MovePrinterMapping.vbs |
' This script is best used within or called by a logon script.
' It allows you to remap printers to a new print server or to new printer on
' the same server. Make sure when using this script, that you have the same
' number of printer mappings listed in both arrays, and that the intPrinters
' variable is also set to the number of items in both arrays.
' For this and other interesting scripts, visit www.RichSchreiber.com
Option Explicit
On Error Resume Next
Dim oNetwork, oPrinter, oItem, oWMIService
Dim strOldServer, strNewServer, strDefaultName, strComputer
Dim colItems, i, intPrinters, intDrive
strOldServer = Array("\\OldServerName\Printer1","\\OldServerName\Printer2", _
"\\ServerName\OldPrinterName")
strNewServer = Array("\\NewServerName\Printer1","\\NewServerName\Printer2", _
"\\ServerName\NewPrinterName")
' How many printers in array?
intPrinters = 3
' Find the current default printer
strComputer = "."
Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = oWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each oItem in colItems
If oItem.Default Then
strDefaultName = oItem.Name
End If
Next
Set oNetwork = CreateObject("WScript.Network")
Set oPrinter = oNetwork.EnumPrinterConnections
' Loop through printers and delete printers if they exist
For intDrive = 0 To (oPrinter.Count -1) Step 2
For i = 0 to intPrinters-1
if oPrinter.Item(intDrive+1) = strOldServer(i) then
oNetwork.RemovePrinterConnection strOldServer(i)
oNetwork.AddWindowsPrinterConnection strNewServer(i)
If LCase(strOldServer(i)) = LCase(strDefaultName) Then
oNetwork.SetDefaultPrinter strNewServer(i)
End If
End if
Next
Next
WScript.Quit