joehare
asked on
VB script to change work station printer mapping after server rename - including printer name change
I previously asked this question :
My environment has approx 100 workstations (XP SP2) and 1 main file server (2003 server)
The file server has 10 printers shared off it that the workstations connect to depending on which ones are closest.
The file server name is being changed to fit in with our new naming conventions.
I need to find a way (preferably a run once method) that I can change the current network printer mappings on the workstations to point to the new server name.
E.g. Change //oldfileserver01/printers hare --> //newfileserver01/printers hare
Ideally it could be a script that wne out and change the old server name for the new server name.
I don't know if this can be done just once (ideal) or if I'd have to put a GPO linked script in place to map the printer share every time a user logged on.
Can somebody help point me in the right direction here? I know I can use something like :
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
WshNetwork.AddWindowsPrint erConnecti on "\\fileserver01\HP500"
WshNetwork.SetDefaultPrint er "\\fileserver01\HP500"
but I'd really like to find a way to just run a script once and have the mapping changed on all the workstations. Any further printer changes can be manually in the future.
I'm pretty good on the windows admin side of things but scripting was never my strong point.
And received this solution from wingatesl :
Here is a link to the VBscript you desire
http://lordoftheping.blogspot.com/2007/09/vbscript-to-change-printer-server.html
I now have the added difficulty of having to change the printer names to the new standard as well. Some of the wotrkstations can have up to 5 printers installed (all from the same print server)
I need a vbs script that will allow me to rename printers and servers. Preferably something that could use a cvs file to match the old and new printer names.
Any ideas?
My environment has approx 100 workstations (XP SP2) and 1 main file server (2003 server)
The file server has 10 printers shared off it that the workstations connect to depending on which ones are closest.
The file server name is being changed to fit in with our new naming conventions.
I need to find a way (preferably a run once method) that I can change the current network printer mappings on the workstations to point to the new server name.
E.g. Change //oldfileserver01/printers
Ideally it could be a script that wne out and change the old server name for the new server name.
I don't know if this can be done just once (ideal) or if I'd have to put a GPO linked script in place to map the printer share every time a user logged on.
Can somebody help point me in the right direction here? I know I can use something like :
Set WshNetwork = WScript.CreateObject("WScr
WshNetwork.AddWindowsPrint
WshNetwork.SetDefaultPrint
but I'd really like to find a way to just run a script once and have the mapping changed on all the workstations. Any further printer changes can be manually in the future.
I'm pretty good on the windows admin side of things but scripting was never my strong point.
And received this solution from wingatesl :
Here is a link to the VBscript you desire
http://lordoftheping.blogspot.com/2007/09/vbscript-to-change-printer-server.html
I now have the added difficulty of having to change the printer names to the new standard as well. Some of the wotrkstations can have up to 5 printers installed (all from the same print server)
I need a vbs script that will allow me to rename printers and servers. Preferably something that could use a cvs file to match the old and new printer names.
Any ideas?
Hi, here is a script that I developed for this exact task, which runs as a Group Policy logon script for every user, every time they log on. This I feel is a safer way of ensuring you reach all users, especially if they log onto different computers.
It gets the client's IP Address, and changes the mappings only if they're in a specific subnet.
Then you define arrPrinterShares as your printer array separating the old printer, with the new printer, by a colon symbol ( : ).
Then it appends to a text file at the location of strLogFileShare, which is called the user name. This username.txt file logs the actions that occurred.
'====================
strComputer = "."
strLogFileShare = "\\FileServer\userlogins$\ PRINTSVR1_ printer_ch anges\"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const intForAppending = 8
Set objShell = CreateObject("WScript.Shel l")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colComputerIP = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfig uration")
For Each IPConfig in colComputerIP
If Not IsNull(IPConfig.IPAddress) Then
For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
strIPAddress = strIPAddress & "IP Address: " & IPConfig.IPAddress(intIPCo unt) & "~"
Next
End If
Next
If InStr(strIPAddress, "172.16.2.") > 0 Then
strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "172.16.2."), InStr(InStr(strIPAddress, "172.16.2."), strIPAddress, "~") - InStr(strIPAddress, "172.16.2."))
ElseIf InStr(strIPAddress, "192.168.20.") > 0 Then
strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.20."), InStr(InStr(strIPAddress, "192.168.20."), strIPAddress, "~") - InStr(strIPAddress, "192.168.20."))
ElseIf InStr(strIPAddress, "192.168.95.") > 0 Then
strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.95."), InStr(InStr(strIPAddress, "192.168.95."), strIPAddress, "~") - InStr(strIPAddress, "192.168.95."))
Else
strTheIPAddress = "UNKNOWN"
End If
If Len(strTheIPAddress) > 1 And Right(strTheIPAddress, 1) = "~" Then
strTheIPAddress = Left(strTheIPAddress, Len(strTheIPAddress) - 1)
End If
If Left(strTheIPAddress, 11) = "192.168.20." Then
arrPrinterShares = Array( _
"\\PRINTSVR1\CroydonCivic_ LocalLaws1 :\\PRINTSV R2\Croydon Civic_Neig hborhoodSe rvices1", _
"\\PRINTSVR1\By_Laws_2300L H:\\PRINTS VR2\Croydo nCivic_Nei ghborhoodS ervices1", _
"\\PRINTSVR1\By_Laws_2300: \\PRINTSVR 2\CroydonC ivic_Neigh borhoodSer vices1", _
"\\PRINTSVR1\CroydonCivic_ Neighborho odServices 1:\\PRINTS VR2\Croydo nCivic_Nei ghborhoodS ervices1", _
"\\PRINTSVR1\Leisure lj2430:\\PRINTSVR2\Croydon Leisure_Le isureFacil ities", _
"\\PRINTSVR1\Rates printer LJ 8150:\\PRINTSVR2\CroydonCi vic_Rates1 ", _
"\\PRINTSVR1\CroydonCivic_ Rates1:\\P RINTSVR2\C roydonCivi c_Rates1", _
"\\PRINTSVR1\CroydonCivic_ Waste:\\PR INTSVR2\Cr oydonCivic _Waste", _
"\\PRINTSVR1\HP LaserJet 2100 PCL6:\\PRINTSVR2\CroydonCi vic_Custom erService2 ", _
"\\PRINTSVR1\CroydonCivic_ CustomerSe rvice2:\\P RINTSVR2\C roydonCivi c_Customer Service2", _
"\\PRINTSVR1\HP LaserJet 2430 PCL 6:\\PRINTSVR2\CroydonCivic _Health1", _
"\\PRINTSVR1\CroydonCivic_ Health1:\\ PRINTSVR2\ CroydonCiv ic_Health1 ", _
"\\PRINTSVR1\CroydonCivic_ CustomerSe rvice1:\\P RINTSVR2\C roydonCivi c_Customer Service1", _
"\\PRINTSVR1\Croydon Civic Cust service 2300:\\PRINTSVR2\CroydonCi vic_Custom erService1 ", _
"\\PRINTSVR1\CroydonCivic_ Neighborho odServices 2:\\PRINTS VR2\Croydo nCivic_Nei ghborhoodS ervices2", _
"\\PRINTSVR1\FX Document Centre C360 PCL 6:\\PRINTSVR2\CroydonCivic _FX_Docume nt_Centre_ C360", _
"\\PRINTSVR1\FX DocuCentre-II C3000 PCL 6:\\PRINTSVR2\CroydonLeisu re_FX_Docu Centre_II_ C3000", _
"\\PRINTSVR1\CroydonCivic_ FXDocumentCentre:\\PRINTSV R2\Croydon Leisure_FX _DocuCentr e_II_C3000 " _
)
Set objNetwork = CreateObject("WScript.Netw ork")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = False")
strLogFile = strLogFileShare & objNetwork.UserName & ".txt"
Set objOutputFile = objFSO.OpenTextFile(strLog File, intForAppending, True)
objOutputFile.WriteLine "Logged in at: " & Now & " on " & objNetwork.ComputerName
On Error Resume Next
If colPrinters.Count <> 0 Then
For Each objPrinter In colPrinters
For intPrinter = LBound(arrPrinterShares) To UBound(arrPrinterShares)
strOldPrinter = Split(arrPrinterShares(int Printer), ":")(0)
strNewPrinter = Split(arrPrinterShares(int Printer), ":")(1)
boolManual = False
If Left(strOldPrinter, 7) = "MANUAL=" Then
boolManual = True
strOldPrinter = Replace(strOldPrinter, "MANUAL=", "")
End If
If UCase(objPrinter.DeviceID) = UCase(strOldPrinter) Then
If boolManual = True Then
objOutputFile.WriteLine "MANUAL: Please obtain the account code for the printing from " & objPrinter.DeviceID & " and then replace that with " & strNewPrinter & " and set the account code."
ElseIf objPrinter.Default = True Then
objNetwork.RemovePrinterCo nnection objPrinter.DeviceID, True, True
objNetwork.AddWindowsPrint erConnecti on strNewPrinter
objNetwork.SetDefaultPrint er strNewPrinter
objOutputFile.WriteLine "Replaced " & objPrinter.DeviceID & " with " & strNewPrinter & " and set it as default"
Else
objNetwork.RemovePrinterCo nnection objPrinter.DeviceID, True, True
objNetwork.AddWindowsPrint erConnecti on strNewPrinter
objOutputFile.WriteLine "Replaced " & objPrinter.DeviceID & " with " & strNewPrinter
End If
End If
Next
If Err.Number <> 0 Then
objOutputFile.WriteLine Err.Number & ": " & Err.Description & VbCrLf & objPrinter.DeviceID & " --> " & strNewPrinter
Err.Clear
End If
Next
End If
Err.Clear
On Error GoTo 0
objOutputFile.Close
Set objOutputFile = Nothing
'MsgBox "Done"
Else
'MsgBox "You are not located at the Croydon Civic offices." & VbCrLf & "Your IP Address is: " & strTheIPAddress
End If
'===============
I hope that suits your needs.
Regards,
Rob.
It gets the client's IP Address, and changes the mappings only if they're in a specific subnet.
Then you define arrPrinterShares as your printer array separating the old printer, with the new printer, by a colon symbol ( : ).
Then it appends to a text file at the location of strLogFileShare, which is called the user name. This username.txt file logs the actions that occurred.
'====================
strComputer = "."
strLogFileShare = "\\FileServer\userlogins$\
Set objFSO = CreateObject("Scripting.Fi
Const intForAppending = 8
Set objShell = CreateObject("WScript.Shel
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set colComputerIP = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfig
For Each IPConfig in colComputerIP
If Not IsNull(IPConfig.IPAddress)
For intIPCount = LBound(IPConfig.IPAddress)
strIPAddress = strIPAddress & "IP Address: " & IPConfig.IPAddress(intIPCo
Next
End If
Next
If InStr(strIPAddress, "172.16.2.") > 0 Then
strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "172.16.2."), InStr(InStr(strIPAddress, "172.16.2."), strIPAddress, "~") - InStr(strIPAddress, "172.16.2."))
ElseIf InStr(strIPAddress, "192.168.20.") > 0 Then
strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.20."), InStr(InStr(strIPAddress, "192.168.20."), strIPAddress, "~") - InStr(strIPAddress, "192.168.20."))
ElseIf InStr(strIPAddress, "192.168.95.") > 0 Then
strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.95."), InStr(InStr(strIPAddress, "192.168.95."), strIPAddress, "~") - InStr(strIPAddress, "192.168.95."))
Else
strTheIPAddress = "UNKNOWN"
End If
If Len(strTheIPAddress) > 1 And Right(strTheIPAddress, 1) = "~" Then
strTheIPAddress = Left(strTheIPAddress, Len(strTheIPAddress) - 1)
End If
If Left(strTheIPAddress, 11) = "192.168.20." Then
arrPrinterShares = Array( _
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\By_Laws_2300L
"\\PRINTSVR1\By_Laws_2300:
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\Leisure lj2430:\\PRINTSVR2\Croydon
"\\PRINTSVR1\Rates printer LJ 8150:\\PRINTSVR2\CroydonCi
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\HP LaserJet 2100 PCL6:\\PRINTSVR2\CroydonCi
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\HP LaserJet 2430 PCL 6:\\PRINTSVR2\CroydonCivic
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\Croydon Civic Cust service 2300:\\PRINTSVR2\CroydonCi
"\\PRINTSVR1\CroydonCivic_
"\\PRINTSVR1\FX Document Centre C360 PCL 6:\\PRINTSVR2\CroydonCivic
"\\PRINTSVR1\FX DocuCentre-II C3000 PCL 6:\\PRINTSVR2\CroydonLeisu
"\\PRINTSVR1\CroydonCivic_
)
Set objNetwork = CreateObject("WScript.Netw
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = False")
strLogFile = strLogFileShare & objNetwork.UserName & ".txt"
Set objOutputFile = objFSO.OpenTextFile(strLog
objOutputFile.WriteLine "Logged in at: " & Now & " on " & objNetwork.ComputerName
On Error Resume Next
If colPrinters.Count <> 0 Then
For Each objPrinter In colPrinters
For intPrinter = LBound(arrPrinterShares) To UBound(arrPrinterShares)
strOldPrinter = Split(arrPrinterShares(int
strNewPrinter = Split(arrPrinterShares(int
boolManual = False
If Left(strOldPrinter, 7) = "MANUAL=" Then
boolManual = True
strOldPrinter = Replace(strOldPrinter, "MANUAL=", "")
End If
If UCase(objPrinter.DeviceID)
If boolManual = True Then
objOutputFile.WriteLine "MANUAL: Please obtain the account code for the printing from " & objPrinter.DeviceID & " and then replace that with " & strNewPrinter & " and set the account code."
ElseIf objPrinter.Default = True Then
objNetwork.RemovePrinterCo
objNetwork.AddWindowsPrint
objNetwork.SetDefaultPrint
objOutputFile.WriteLine "Replaced " & objPrinter.DeviceID & " with " & strNewPrinter & " and set it as default"
Else
objNetwork.RemovePrinterCo
objNetwork.AddWindowsPrint
objOutputFile.WriteLine "Replaced " & objPrinter.DeviceID & " with " & strNewPrinter
End If
End If
Next
If Err.Number <> 0 Then
objOutputFile.WriteLine Err.Number & ": " & Err.Description & VbCrLf & objPrinter.DeviceID & " --> " & strNewPrinter
Err.Clear
End If
Next
End If
Err.Clear
On Error GoTo 0
objOutputFile.Close
Set objOutputFile = Nothing
'MsgBox "Done"
Else
'MsgBox "You are not located at the Croydon Civic offices." & VbCrLf & "Your IP Address is: " & strTheIPAddress
End If
'===============
I hope that suits your needs.
Regards,
Rob.
ASKER
RobSampson:
That's almost exactly what I need. I had planned on putting the script in GPO and filtering it based on security group.
How do I go about removing the IP address filter from your script?
That's almost exactly what I need. I had planned on putting the script in GPO and filtering it based on security group.
How do I go about removing the IP address filter from your script?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rob you're a star.
Thank you very much. THis will save me a LOT of footwork.
Joe
Thank you very much. THis will save me a LOT of footwork.
Joe
No problem....good luck with it. It saved us a LOT of time as well!
Regards,
Rob.
Regards,
Rob.
Hi,
i've used this script numerous times with great success. However i am now trying to move ALL our printers to another print server and the script seems to have problem with this line:
"\\SRV-001\SB_DT6180PS_DEC OMPFF1B:\\ SRV-005\SB _DT6180PS_ DECOMPFF1B ", _
My guess is that the share and printer name are too long. I don't know if i'm right though. If it's the case is there any way to adapt the script so it can work? If now any of you guys have ideas on why it doesn't work? Thanks in advance...
i've used this script numerous times with great success. However i am now trying to move ALL our printers to another print server and the script seems to have problem with this line:
"\\SRV-001\SB_DT6180PS_DEC
My guess is that the share and printer name are too long. I don't know if i'm right though. If it's the case is there any way to adapt the script so it can work? If now any of you guys have ideas on why it doesn't work? Thanks in advance...
I actually made a mistake. Here is my entire script. it gives syntax error at line 88 character 1. I am clueless right now.
'====================
strComputer = "."
strLogFileShare = "\\srv-009\logs\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForAppending = 8
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
arrPrinterShares = Array( _
"\\SRV-001\Bon de livraison numérique:\\SRV-005\Bon de livraison numérique", _
"\\SRV-001\Bon de livraison numérique2:\\SRV-005\Bon de livraison numérique2", _
"\\SRV-001\DC5000_H:\\SRV-005\DC5000_H", _
"\\SRV-001\DOS-XEROX:\\SRV-005\DOS-XEROX", _
"\\SRV-001\DT6135A:\\SRV-005\DT6135A", _
"\\SRV-001\DT6135B:\\SRV-005\DT6135B", _
"\\SRV-001\Facture numérique:\\SRV-005\Facture numérique", _
"\\SRV-001\Facture numérique2:\\SRV-005\Facture numérique2", _
"\\SRV-001\Facture numérique3:\\SRV-005\Facture numérique3", _
"\\SRV-001\Feuille de travail numérique:\\SRV-005\Feuille de travail numérique", _
"\\SRV-001\Feuille de travail numérique2:\\SRV-005\Feuille de travail numérique2", _
"\\SRV-001\Lexmark_E120n:\\SRV-005\Lexmark_E120n", _
"\\SRV-001\N120-1:\\SRV-005\N120-1", _
"\\SRV-001\N120-2:\\SRV-005\N120-2", _
"\\SRV-001\N120-3:\\SRV-005\N120-3", _
"\\SRV-001\N120-4:\\SRV-005\N120-4", _
"\\SRV-001\N4110-1:\\SRV-005\N4110-1", _
"\\SRV-001\N4110-1PS:\\SRV-005\N4110-1PS", _
"\\SRV-001\N4110-2:\\SRV-005\N4110-2", _
"\\SRV-001\N6180-1_decompff1:\\SRV-005\N6180-1_decompff1", _
"\\SRV-001\N6180-1_decompff2:\\SRV-005\N6180-1_decompff2", _
"\\SRV-001\N6180-1_hold:\\SRV-005\N6180-1_hold", _
"\\SRV-001\NA_HP4PCL:\\SRV-005\NA_HP4PCL", _
"\\SRV-001\NB_BIGDOCKET:\\SRV-005\NB_BIGDOCKET", _
"\\SRV-001\NB_HP5100PCL:\\SRV-005\NB_HP5100PCL", _
"\\SRV-001\NB_HP5100PS:\\SRV-005\NB_HP5100PS", _
"\\SRV-001\NB_MINIDOCKET:\\SRV-005\NB_MINIDOCKET", _
"\\SRV-001\NC_5000PCL:\\SRV-005\NC_5000PCL", _
"\\SRV-001\NC_5000PS:\\SRV-005\NC_5000PS", _
"\\SRV-001\ND_5SIMXPCL:\\SRV-005\ND_5SIMXPCL", _
"\\SRV-001\ND_5SIMXPS:\\SRV-005\ND_5SIMXPS", _
"\\SRV-001\NE_8100-LGL:\\SRV-005\NE_8100-LGL", _
"\\SRV-001\NE_8100PCL:\\SRV-005\NE_8100PCL", _
"\\SRV-001\NE_8100PS:\\SRV-005\NE_8100PS", _
"\\SRV-001\NE_BIGDOCKET-FRONT:\\SRV-005\NE_BIGDOCKET-FRONT", _
"\\SRV-001\NE_MINIDOCKET-FRONT:\\SRV-005\NE_MINIDOCKET-FRONT", _
"\\SRV-001\NF_C4500PCL:\\SRV-005\NF_C4500PCL", _
"\\SRV-001\NF_C4500PS:\\SRV-005\NF_C4500PS", _
"\\SRV-001\NG_HP5PCL:\\SRV-005\NG_HP5PCL", _
"\\SRV-001\NH_XDC432PCL:\\SRV-005\NH_XDC432PCL", _
"\\SRV-001\NH_XDC432PS:\\SRV-005\NH_XDC432PS", _
"\\SRV-001\NI_8000PCL:\\SRV-005\NI8000_PCL", _
"\\SRV-001\NI_8000PS:\\SRV-005\NI_8000PS", _
"\\SRV-001\NJ_5SIPCL:\\SRV-005\NJ_5SIPCL", _
"\\SRV-001\NJ_5SIPS:\\SRV-005\NJ_5SIPS", _
"\\SRV-001\NK_5100PCL:\\SRV-005\NK_5100PCL", _
"\\SRV-001\NK_5100PS:\\SRV-005\NK_5100PS", _
"\\SRV-001\NK_BIGDOCKET:\\SRV-005\NK_BIGDOCKET", _
"\\SRV-001\NK_MINIDOCKET:\\SRV-005\NK_MINIDOCKET", _
"\\SRV-001\NM_470STPCL:\\SRV-005\NM_470STPCL", _
"\\SRV-001\NM_470STPS:\\SRV-005\NM_470STPs", _
"\\SRV-001\NM_IR550CPCL:\\SRV-005\NM_IR550CPCL", _
"\\SRV-001\NM_IR550CPS:\\SRV-005\NM_IR550CPS", _
"\\SRV-001\NN_IR550:\\SRV-005\NN_IR550", _
"\\SRV-001\NN_IR550DPS:\\SRV-005\NN_IR550DPS", _
"\\SRV-001\NN_IR550PS:\\SRV-005\NN_IR550PS", _
"\\SRV-001\NP_5000PCL:\\SRV-005\NP_5000PCL", _
"\\SRV-001\NP_5000PS:\\SRV-005\NP_5000PS", _
"\\SRV-001\NQ_B4250:\\SRV-005\NQ_B4250", _
"\\SRV-001\NR_2060PS:\\SRV-005\NR_2060PS", _
"\\SRV-001\NS_2240PCL:\\SRV-005\NS_2240PCL", _
"\\SRV-001\NS_2240PS:\\SRV-005\NS_2240PS", _
"\\SRV-001\NZ_Docucolor12:\\SRV-005\NZ_Docucolor12", _
"\\SRV-001\SA_DT6180PS_DECOMPFF1A:\\SRV-005\SA_DT6180PS_DECOMPFF1A", _
"\\SRV-001\SA_DT6180PS_DECOMPFF2A:\\SRV-005\SA_DT6180PS_DECOMPFF2A", _
"\\SRV-001\SA_DT6180PS_DECOMPFF3A:\\SRV-005\SA_DT6180PS_DECOMPFF3A", _
"\\SRV-001\SA_DT6180PS_DT:\\SRV-005\SA_DT6180PS_DT", _
"\\SRV-001\SB_DT6180PS_DECOMPFF1B:\\SRV-005\SB_DT6180PS_DECOMPFF1B", _
"\\SRV-001\SB_DT6180PS_DECOMPFF2B:\\SRV-005\SB_DT6180PS_DECOMPFF2B", _
"\\SRV-001\SB_DT6180PS_DECOMPFF3B:\\SRV-005\SB_DT6180PS_DECOMPFF3B", _
"\\SRV-001\SB_DT6180PS_DT:\\SRV-005\SB_DT6180PS_DT", _
"\\SRV-001\SC_DT6180PS_DECOMPFF1C:\\SRV-005\SC_DT6180PS_DECOMPFF1C", _
"\\SRV-001\SC_DT6180PS_DECOMPFF2C:\\SRV-005\SC_DT6180PS_DECOMPFF2C", _
"\\SRV-001\SC_DT6180PS_DECOMPFF3C:\\SRV-005\SC_DT6180PS_DECOMPFF3C", _
"\\SRV-001\SC_DT6180PS_DT:\\SRV-005\SC_DT6180PS_DT", _
"\\SRV-001\SD_DT6180PS_DECOMPFF1D:\\SRV-005\SD_DT6180PS_DECOMPFF1D", _
"\\SRV-001\SD_DT6180PS_DECOMPFF2D:\\SRV-005\SD_DT6180PS_DECOMPFF2D", _
"\\SRV-001\SD_DT6180PS_DECOMPFF3D:\\SRV-005\SD_DT6180PS_DECOMPFF3D", _
"\\SRV-001\SD_DT6180PS_DT:\\SRV-005\SD_DT6180PS_DT", _
"\\SRV-001\SE_DT6180PS_DECOMPFF1E:\\SRV-005\SE_DT6180PS_DECOMPFF1E", _
"\\SRV-001\SE_DT6180PS_DECOMPFF2E:\\SRV-005\SE_DT6180PS_DECOMPFF2E", _
"\\SRV-001\SE_DT6180PS_DECOMPFF3E:\\SRV-005\SE_DT6180PS_DECOMPFF3E", _
"\\SRV-001\SE_DT6180PS_DT:\\SRV-005\SE_DT6180PS_DT", _
"\\SRV-001\SF_DT6180PS_DT:\\SRV-005\SF_DT6180PS_DT", _
"\\SRV-001\SG_4110A:\\SRV-005\SG_4110A", _
"\\SRV-001\SH_4110B:\\SRV-005\SH_4110B", _
"\\SRV-001\SM_HP5100PCL:\\SRV-005\SM_HP5100PCL", _
"\\SRV-001\SM_HP5100PCL_Docket:\\SRV-005\SM_HP5100PCL_Docket", _
"\\SRV-001\SM_HP5100PCL_MiniDocket:\\SRV-005\SM_HP5100PCL_MiniDocket", _
"\\SRV-001\SN_HP5000PCL:\\SRV-005\SN_HP5000PCL", _
"\\SRV-001\SO_HP3380PCL:\\SRV-005\SO_HP3380PCL", _
"\\SRV-001\SO_HP3380PS:\\SRV-005\SO_HP3380PS", _
"\\SRV-001\SP_DC12PCL_H:\\SRV-005\SP_DC12PCL_H", _
"\\SRV-001\SP_DC12PCL_P:\\SRV-005\SP_DC12PCL_P", _
"\\SRV-001\SP_DC12PS_H:\\SRV-005\SP_DC12PS_H", _
"\\SRV-001\SP_DC12PS_P:\\SRV-005\SP_DC12PS_P", _
"\\SRV-001\SQ_HP4050PCL:\\SRV-005\SQ_HP4050PCL", _
"\\SRV-001\SQ_HP4050PCL-FACT:\\SRV-005\SQ_HP4050PCL-FACT", _
"\\SRV-001\SQ_HP4050PS:\\SRV-005\SQ_HP4050PS", _
"\\SRV-001\SQ_HP4050PS-LGL:\\SRV-005\SQ_HP4050PS-LGL", _
"\\SRV-001\SR_GP200PCL:\\SRV-005\SR_GP200PCL", _
"\\SRV-001\SR_GP200PS:\\SRV-005\SR_GP200PS", _
"\\SRV-001\SS_DC6060PS_H:\\SRV-005\SS_DC6060PS_H", _
"\\SRV-001\ST_DC2060PS_H:\\SRV-005\ST_DC2060PS_H", _
"\\SRV-001\ST_DC2060PS_P:\\SRV-005\ST_DC2060PS_P", _
"\\SRV-001\SU_IGEN3PS_H:\\SRV-005\SU_IGEN3PS_H" _
)
Set objNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = False")
strLogFile = strLogFileShare & objNetwork.UserName & ".txt"
Set objOutputFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
objOutputFile.WriteLine "Logged in at: " & Now & " on " & objNetwork.ComputerName
On Error Resume Next
If colPrinters.Count <> 0 Then
For Each objPrinter In colPrinters
For intPrinter = LBound(arrPrinterShares) To UBound(arrPrinterShares)
strOldPrinter = Split(arrPrinterShares(intPrinter), ":")(0)
strNewPrinter = Split(arrPrinterShares(intPrinter), ":")(1)
boolManual = False
If Left(strOldPrinter, 7) = "MANUAL=" Then
boolManual = True
strOldPrinter = Replace(strOldPrinter, "MANUAL=", "")
End If
If UCase(objPrinter.DeviceID) = UCase(strOldPrinter) Then
If boolManual = True Then
objOutputFile.WriteLine "MANUAL: Please obtain the account code for the printing from " & objPrinter.DeviceID & " and then replace that with " & strNewPrinter & " and set the account code."
ElseIf objPrinter.Default = True Then
objNetwork.RemovePrinterConnection objPrinter.DeviceID, True, True
objNetwork.AddWindowsPrinterConnection strNewPrinter
objNetwork.SetDefaultPrinter strNewPrinter
objOutputFile.WriteLine "Replaced " & objPrinter.DeviceID & " with " & strNewPrinter & " and set it as default"
Else
objNetwork.RemovePrinterConnection objPrinter.DeviceID, True, True
objNetwork.AddWindowsPrinterConnection strNewPrinter
objOutputFile.WriteLine "Replaced " & objPrinter.DeviceID & " with " & strNewPrinter
End If
End If
Next
If Err.Number <> 0 Then
objOutputFile.WriteLine Err.Number & ": " & Err.Description & VbCrLf & objPrinter.DeviceID & " --> " & strNewPrinter
Err.Clear
End If
Next
End If
Err.Clear
On Error GoTo 0
objOutputFile.Close
Set objOutputFile = Nothing
'MsgBox "Done"
'===============
I guess my problem is solved now. I couldn't see what turned out to be blank lines in notepad. I fixed it now.
I have a slightly different error. This script is absolutely quality!! However, a couple of machines are producing the following error in their log files...
Replaced \\hbc001\IDB_SH_GND with \\HBCPRINT\IDB_SH_GND
Replaced \\hbc001\INF_4250 with \\HBCPRINT\INF_4250 and set it as default
"462: The remote server machine does not exist or is unavailable
\\hbc001\INF_4250 --> \\HBCPRINT\HR_MGR_4250"
This doesn't happen to all machines and there is nothing I can see ties any of the machines together...
Any ideas??
Replaced \\hbc001\IDB_SH_GND with \\HBCPRINT\IDB_SH_GND
Replaced \\hbc001\INF_4250 with \\HBCPRINT\INF_4250 and set it as default
"462: The remote server machine does not exist or is unavailable
\\hbc001\INF_4250 --> \\HBCPRINT\HR_MGR_4250"
This doesn't happen to all machines and there is nothing I can see ties any of the machines together...
Any ideas??
I have tried this script on windows 7 and it keeps erroring on line 13 character 7 which it the )
Any idea why it has trouble with that character? Have tried removing it, re-typing it, and moving it around thinking it is a formatting issue but haven't got it to work
Any idea why it has trouble with that character? Have tried removing it, re-typing it, and moving it around thinking it is a formatting issue but haven't got it to work
http://msdn2.microsoft.com/en-us/library/aa394598.aspx
Jeroen