Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unmap/remap network printers with a script without Admin privileges

Posted on 2014-04-26
10
Medium Priority
?
1,628 Views
Last Modified: 2014-05-10
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?
0
Comment
Question by:bozworthy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 25

Expert Comment

by:Mohammed Khawaja
ID: 40025138
We did the same for users at work and we wrote a script.  I will post the script next week.
0
 
LVL 31

Expert Comment

by:Gareth Gudger
ID: 40025269
If you are using Server 2008 R2 or newer domain controllers you can easily do this with Group Policies.

See the screenshot. It's very easy to do. The user does not need admin rights. Its all automated.

GPO Printers
0
 
LVL 56

Expert Comment

by:McKnife
ID: 40027740
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:bozworthy
ID: 40032614
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?
0
 
LVL 31

Expert Comment

by:Gareth Gudger
ID: 40033105
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.
0
 
LVL 25

Expert Comment

by:Mohammed Khawaja
ID: 40034788
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.FileSystemObject")

For Each objPrinter in colPrinters
       sDefaultPrt = objPrinter.Sharename
Next

'Get the currently mapped printers
Set objNetwork = CreateObject("WScript.Network")
Set objPrinter = objNetwork.EnumPrinterConnections
Set WshNetwork = CreateObject("WScript.Network")

Set ts = fso.CreateTextFile("c:\myprinters.txt")

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:\myprinters.txt", 1)

Do While Not ts.AtEndOfStream

      sTemp = ts.ReadLine

      SET ts2 = fso.OpenTextFile("\\servername\sharedname\prnmapping.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.RemovePrinterConnection  sPrt
                  WshNetWork.AddWindowsPrinterConnection sNewPrt
                  'Set as the default if matches the currently mapped default printer
                  If Instr(sPrt, sDefaultPrt)> 0 Then
                        WshNetwork.SetDefaultPrinter sNewPrt
                  End If
                  Exit Do
            End If
       Loop

       ts2.close
Loop

Wscript.Quit(1)
0
 
LVL 1

Accepted Solution

by:
bozworthy earned 0 total points
ID: 40036378
Mohammed, the new print queues were set up on the new server with drivers. A user's mapping would change from \\olderserver\printer to \\newserver\printer.  I was testing a script much like above but the line WshNetWork.AddWindowsPrinterConnection sNewPrt did not add a device to my machine nor did WshNetwork.RemovePrinterConnection  sPrt remove one. Also, wouldn't a user need Admin to run that executable script?

We ended up putting the device list on a website where the user's could choose their device and run a .bat file with PrintUiEntry to add it. Then it was up to them to manually delete any old mappings.
0
 
LVL 56

Expert Comment

by:McKnife
ID: 40040818
Ok fine. Then finalize this question :)
0
 
LVL 1

Author Closing Comment

by:bozworthy
ID: 40055662
Given the admin constraint and time concerns, this is what we ended up doing.
0
 
LVL 25

Expert Comment

by:Mohammed Khawaja
ID: 40056128
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.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question