How do I remove a printer connection without the user's intervention?

15,916

Solution 1

Group Policy Printer Preferences contains a "Delete" option. If you're deploying the new printers with a GPP GPO, you can add the Delete items to the end of it, or create a whole new Delete Printers GPO.

I just did a transition like this for about 75 printers and it went very smoothly. We have one Deploy Printers GPO linked at the domain level with all of the printers in it, and mappings are controlled via group membership using Item Level Targeting. We also have a Deleted Printers GPO at the domain level that has all of the old printers on the old print server on it. I didn't bother filtering this, because there's really no need. If it's old and it's mapped, it's got to go!

The good thing about GPP items is that they are run at policy refresh intervals, meaning that no logon/logoff/reboot is required. Just configure the policy, link it, and sit back. No messing with scripts or WMI or any of that.

Solution 2

Actually removing the printers is the easy part.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
    ("Select * From Win32_Printer Where Network = True")

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

The difficult (or at least pain-in-the-ass) part is pushing that out to all the users without them having to do something (like rebooting). Frankly, my solution would be to send an email telling the users to reboot to get the new printers mapped. That way you can put the printer removal script into the Run Once registry setting via GPO, and map the new printers via GPP afterwards.

If you have a smaller or well-organized environment, you could always run a script to push that out to all your user workstations with psexec (would require a .csv or other delimited text file with a list of your workstations), but again, that seems like more of a pain that it's worth, and my preference would be to just tell the users to reboot.

Share:
15,916

Related videos on Youtube

1.618
Author by

1.618

Professional Software Developer SOreadytohelp

Updated on September 18, 2022

Comments

  • 1.618
    1.618 almost 2 years

    Here's the situation: We're replacing 11 printers with newer models, and we'll be installing them on our print server and sharing them out. The plan is to share the new printers under different names than the ones they're replacing, and un-share the old ones.

    So I need to come up with a way to remove the client connections to old printers automatically. Clients are mostly Windows 7 with a few XP.

    My first idea was to call prnmngr.vbs from the login script to remove each old printer explicitly by name. The problem is that some users don't log out when they're done for the day, so I can't count on their login script running before they next need to print. I could remotely run prnmngr.vbs using SCCM, but if it's not 'impersonating' the user, I don't think it will remove their printers. Any ideas? Could I lookup how to access WMI using c# code and write a "trojan" to remove specific printers without requiring the user to do anything? (I'm only half joking).

    I'm open to any suggestion! Thanks!

  • 1.618
    1.618 over 11 years
    We've been using GPOs to deploy printer connections to some users, but I didn't know it could also be used to remove them -- thanks! But it doesn't work with XP, right?
  • Greg Askew
    Greg Askew over 11 years
    @1.618: There is a GP Preferences client extension for XP, cant vouch for it though. I seldom work with the legacy os's any longer.
  • MDMarra
    MDMarra over 11 years