Sep 1, 2011

Simple Batch Script for Remapping Network Printers

I am trying to eradicate all the remaining Windows 2008 domain controllers in my environment so I can upgrade the functional level of my domain to Windows 2008 R2 native. The only thing in my way? One lowsy Windows 2008 domain controller that also doubles as a print server.

I decided to deploy some new Windows 2008 R2 domain controllers running on Windows 2008 R2 Core to save on resources, and on one of them I installed the Printer Services role. As anyone who has ever replaced a print server in an office knows, the easy part is setting up the new server. The hard part is remapping everyone to the new print server.

I have seen a lot of VBS scripts that perform this task, which is fine, but in my opinion VBS scripts can be unnecessarily complicated, especially if it can be done with a batch script instead. Batch scripts are just easier.

Anyway, If you want to remove a network printer, then add a new one and mark it as default you only need three lines of code. Ready? Here you go:

rundll32 printui.dll,PrintUIEntry /dn /q /n\\oldservename\oldprintername

rundll32 printui.dll,PrintUIEntry /in /q /n\\newservername\newprintername

rundll32 printui.dll,PrintUIEntry /y /n\\newservername\newprintername

The first line quietly deletes the old server mapping, the second line maps to the new server, and the last line sets the printer as default. Simple right?

I have tested this on Windows xp, and Windows 7 and it works without a hitch! tags:

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | stopping spam