Change PrintServer2.vbs


‘ Replace printer queues from old server with queues on new server

‘ Created 20090313 by Inge Brattaas (inge@netpower.no)

Option Explicit
On Error Resume Next

‘ ::: Global variables :::
Dim PrintServerOld
PrintServerOld = «\\nt-server-1\»
Dim PrintServerNew
PrintServerNew = «\\thsrv06\»
Dim DefaultPrinterOld
DefaultPrinterOld = GetDefaultPrinter()
Dim DefaultPrinterNew

‘ ::: Global objects :::
Dim wsh
Set wsh = WScript.CreateObject(«WScript.Shell»)
Dim fso
Set fso = CreateObject(«Scripting.FileSystemObject»)
Dim wnet
Set wnet = CreateObject(«Wscript.Network»)

‘ ::: Call procedures :::
ReplacePrinter «BrotherTavle»
ReplacePrinter «hpLJ5000»
ReplacePrinter «DSC224c»
ReplacePrinter «DSC224»
ReplacePrinter «R2032fax»
ReplacePrinter «Ricoh2032»
ReplacePrinter «Rmpc4500c»
ReplacePrinter «Rmpc4500»
ReplacePrinter «RicohFAX»
ReplacePrinter «HP4500PCL»
ReplacePrinter «hpDjT610»

‘ Set new defaultprinter
If Not DefaultPrinterNew = «» Then
wnet.SetDefaultPrinter DefaultPrinterNew
End If

‘ ::: Procedures :::
Sub ReplacePrinter(ByVal PrinterName)
If DefaultPrinterOld = PrintServerOld & PrinterName then _
DefaultPrinterNew = PrintServerNew & PrinterName
wnet.RemovePrinterConnection PrintServerOld & PrinterName
wnet.AddWindowsPrinterConnection PrintServerNew & PrinterName
End Sub

Function GetDefaultPrinter
Dim strComputer
strComputer = «.»
Dim objWMIService
Set objWMIService = GetObject(«winmgmts:» _
& «{impersonationLevel=impersonate}!\\» & strComputer & «\root\cimv2»)
Dim colInstalledPrinters
Set colInstalledPrinters = objWMIService.ExecQuery _
(«Select * from Win32_Printer where Network = ‘True'»)
Dim objPrinter
For Each objPrinter in colInstalledPrinters
If objprinter.default = «True» Then GetDefaultPrinter = objprinter.name
Exit Function
Next
GetDefaultPrinter = «»
End Function

Tags: , ,
This site is protected by WP-CopyRightPro