Dim strComputer, sPrinterPath, sPrinterName, sOldPrntSrv, sNewPrntSrv
sOldPrntSrv = "OldPrintServer"
sNewPrntSrv = "NewPrintServer"
Set WshNetwork = CreateObject("WScript.Network")
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
sPrinterPath = UCase(objPrinter.Name)
Length = Len(sPrinterPath)
sPrinterName = Right(sPrinterPath,Length - InStrRev(sPrinterPath,"\"))
If Instr(sPrinterPath, sNewPrntSrv) Then
If Length > 27 Then
WshNetwork.RemovePrinterConnection sPrinterPath
WshNetwork.AddWindowsPrinterConnection UCase("\\" & sNewPrntSrv & "\" & sPrinterName)
End If
End If
If Instr(sPrinterPath, sOldPrntSrv) Then
WshNetwork.RemovePrinterConnection sPrinterPath
WshNetwork.AddWindowsPrinterConnection UCase("\\" & sNewPrntSrv & "\" & sPrinterName)
End If
Next
No comments:
Post a Comment