Note that this is a re-post from my article at: http://blogs.msdn.com/b/pfedev/archive/2009/11/25/creating-non-user-specific-printer-mappings.aspx
I was delivering a PowerShell class, and the question of how to create a remote printer mapping came up.
Turns out that enterprise administrators may have the need to help users with their printer connections, setting them up for them.
As I started thinking about the problem, it dawned on me that drive and printer mappings are user specific. They are stored as part of a user’s profile, and since the user profile does not get loaded until the user is actually logged on, looks like little can be done.
Domain user accounts do have a couple of properties that allow administrators to establish a “Home” share, and to assign it a drive letter. Beyond that, they are on their own.
However, there is a solution!
For printers, in particular, turns out that there is a feature that allows setting up a “global” printer mapping. This mapping will be created for the computer, and any user that logs on will be able to use it (provided (s)he has permissions).
The regular Add Printer wizard only allows to create a printer mapping for the user running the wizard:
So that will not help. However, the PrintUI.dll library exposes the functionality to create a computer specific printer mappings!
Simply run the PrintUIEntry (case sensitive) entry point for that library using rundll32 and pass the appropriate parameters… and voilà, the printer mapping is created.
What? How do you do that? Thanks for asking!
Open a PowerShell window (if you still are in the old days, go ahead, use CMD.exe instead) and type:
RunDLL32 PrintUI.dll PrintUIEntry /?
to get a help dialog with information on usage:
To create a global mapping, use the Global Add command with the /n parameter:
RunDLL32 PrintUI.dll PrintUIEntry /ga /n\\SERVER\PRINTER_NAME
To delete the mapping, use the Global Delete command:
RunDLL32 PrintUI.dll PrintUIEntry /gd /n\\SERVER\PRINTER_NAME
If you want to remotely do this on another computer, the usage indicates that you can specify the computer name with the /c parameter:
RunDLL32 PrintUI.dll PrintUIEntry /gd /c\\Computer /n\\SERVER\PRINTER_NAME
However, this didn’t work for me, so I just used the first command but ran it remote”ly using PowerShell:
$p = [WMICLASS]"//COMPUTER/root/CIMv2:WIN32_Process"
$p.Create("RunDLL32 PrintUI.dll PrintUIEntry /ga /n\\SERVER\PRINTER_NAME")
Note: Make sure that the Print Spooler service in the box where the new share was added is restarted after the addition/deletion of the mapping.
I found this to be pretty handy, even in my home network.
Happy printer mapping!