bozworthy
asked on
Unmap/remap network printers with a script without Admin privileges
We have to switch approximately 118 printers from one server to another. The printer names will remain the same. There are 200 users, who do not have Admin privileges on their machines, and are spread out on several floors and could be using a wide range of the 118 printers. We would like to make a switch for them as painless as possible with a single script that could be executed by each user.
Ideally I'd like a script to dynamically unmap a user's old devices then map the new ones. I know a .bat script with PrintUiEntry.dll will work to add or remove if you already know the device names. However I can't find a way to make a single script do this dynamically for each user without writing a VB executable, which they would not be able to run.
Any ideas?
Ideally I'd like a script to dynamically unmap a user's old devices then map the new ones. I know a .bat script with PrintUiEntry.dll will work to add or remove if you already know the device names. However I can't find a way to make a single script do this dynamically for each user without writing a VB executable, which they would not be able to run.
Any ideas?
We did the same for users at work and we wrote a script. I will post the script next week.
And please keep in mind what admin privileges are needed for... NOT for mapping a printer BUT for installing the driver... and that has already happened. So remapping will need no admin rights.
Yes, I did that before.
Yes, I did that before.
ASKER
If understand this correctly it will work....but since we won't know which devices a user has mapped (they might have 5 of the 118 mapped) we would be forced to add all 118 printers to every user. Or am I misunderstanding?
Rather than the "Create" one I have selected in the screenshot, you could do the "Update" one instead. That will only fix the ones they have.
From what you are telling me, the printers were moved and no where was it mentioned if new drivers were created or if the share names were changed. What I would do is the following:
1. Have a script to interrogate all printers installed on user's pc
2. Check against a mapping file
3. Delete printer and installing the corresponding replacement one
Below is the script and the mapping file will contain a line with the old printer shared name, followed by ~ and finally the new shared printer name.
Option Explicit
Dim objNetwork, objPrinter, intDrive, intNetLetter
Dim fso, ts, ts2, sTemp, sTemp2, sPrt, sNewPrt
Dim WshNetwork, strComputer, objWMIService, colPrinters, sDefaultPrt
'Get the default Printer
strComputer = "."
Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer where Default = TRUE")
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
For Each objPrinter in colPrinters
sDefaultPrt = objPrinter.Sharename
Next
'Get the currently mapped printers
Set objNetwork = CreateObject("WScript.Netw ork")
Set objPrinter = objNetwork.EnumPrinterConn ections
Set WshNetwork = CreateObject("WScript.Netw ork")
Set ts = fso.CreateTextFile("c:\myp rinters.tx t")
For intDrive = 0 To (objPrinter.Count -1) Step 2
intNetLetter = IntNetLetter +1
ts.Writeline objPrinter.Item(intDrive +1)
Next
'Find matching printers and remove them
Set ts = fso.OpenTextFile("c:\mypri nters.txt" , 1)
Do While Not ts.AtEndOfStream
sTemp = ts.ReadLine
SET ts2 = fso.OpenTextFile("\\server name\share dname\prnm apping.txt ", 1)
Do While Not ts2.AtEndOfStream
sTemp2 = ts2.ReadLine
sPrt = Left(sTemp2, Instr(sTemp2, "~") - 1)
sNewPrt = Mid(sTemp2, Instr(sTemp2, "~") + 1)
If uCase(sTemp) = uCase(sPrt) Then
WshNetwork.RemovePrinterCo nnection sPrt
WshNetWork.AddWindowsPrint erConnecti on sNewPrt
'Set as the default if matches the currently mapped default printer
If Instr(sPrt, sDefaultPrt)> 0 Then
WshNetwork.SetDefaultPrint er sNewPrt
End If
Exit Do
End If
Loop
ts2.close
Loop
Wscript.Quit(1)
1. Have a script to interrogate all printers installed on user's pc
2. Check against a mapping file
3. Delete printer and installing the corresponding replacement one
Below is the script and the mapping file will contain a line with the old printer shared name, followed by ~ and finally the new shared printer name.
Option Explicit
Dim objNetwork, objPrinter, intDrive, intNetLetter
Dim fso, ts, ts2, sTemp, sTemp2, sPrt, sNewPrt
Dim WshNetwork, strComputer, objWMIService, colPrinters, sDefaultPrt
'Get the default Printer
strComputer = "."
Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer where Default = TRUE")
Set fso = CreateObject("Scripting.Fi
For Each objPrinter in colPrinters
sDefaultPrt = objPrinter.Sharename
Next
'Get the currently mapped printers
Set objNetwork = CreateObject("WScript.Netw
Set objPrinter = objNetwork.EnumPrinterConn
Set WshNetwork = CreateObject("WScript.Netw
Set ts = fso.CreateTextFile("c:\myp
For intDrive = 0 To (objPrinter.Count -1) Step 2
intNetLetter = IntNetLetter +1
ts.Writeline objPrinter.Item(intDrive +1)
Next
'Find matching printers and remove them
Set ts = fso.OpenTextFile("c:\mypri
Do While Not ts.AtEndOfStream
sTemp = ts.ReadLine
SET ts2 = fso.OpenTextFile("\\server
Do While Not ts2.AtEndOfStream
sTemp2 = ts2.ReadLine
sPrt = Left(sTemp2, Instr(sTemp2, "~") - 1)
sNewPrt = Mid(sTemp2, Instr(sTemp2, "~") + 1)
If uCase(sTemp) = uCase(sPrt) Then
WshNetwork.RemovePrinterCo
WshNetWork.AddWindowsPrint
'Set as the default if matches the currently mapped default printer
If Instr(sPrt, sDefaultPrt)> 0 Then
WshNetwork.SetDefaultPrint
End If
Exit Do
End If
Loop
ts2.close
Loop
Wscript.Quit(1)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ok fine. Then finalize this question :)
ASKER
Given the admin constraint and time concerns, this is what we ended up doing.
Our users never had admin rights and you do not need admin rights to connect to a printer. From what I gathered, drivers were already on users PC since you moved printers from one server to another, all that would happen is the OS would connect to the printer using already installed drivers.