Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an XP machine with multiple profiles. These profiles sometimes have different printers mapped to each user. Example:

  • User A has network printer 1, 2 and 5 mapped. Printer 2 is default.
  • User B has network printer 1, 4 and 8 mapped. Printer 4 is default.
  • User C has network printer 2 mapped. Printer 2 is default.

My ideal would be to poll each and every user on the machine, list all the printers they have mapped, and then strip out the duplicates so that I have a list of unique printers mapped to the machine. Ideally I'd like to see which was defaulted most often, but that's totally optional. The list then would look like:


 - Printer 1
 - Printer 2 [Defaulted most often]
 - Printer 4
 - Printer 5
 - Printer 8

I would then like to restore the entire list of printers to each user on their new machine. They are migrating to a new windows 7 machine.

I've figured out how to do this for single user machines, with the following code:

Echo exporting printers
reg export HKCU\Printers\Connections %~d0\%username%\printers.reg
net use >%~d0\%username%\mappings.txt

Echo Importing Printers
reg import %~d0\%username%\printers.reg

The problem is that this works for only one user. I have an admin account, and I would like to get this to work all at once for a multiprofile machine. Please help!

share|improve this question
Can't you just repeat what you have for a single user for all the user subfolders in C:\Documents and Settings? You might want to leave certain harcoded ones out, though, such as Guest. – martineau Dec 11 '12 at 17:54
In the restore I can do that, although it would be nice to get all of them mapped at once. It's mainly the backup that's the problem. I need all the users to have all the printers, and sometimes a user that rarely logged onto this machine might have no printers mapped when they will need some. – Wyko Dec 11 '12 at 18:13

To access the registry keys of the other users on the system you will have to load the registry hive per each user. See reg /? The user's hive file NTUser.dat will be located at the base of each user's directory. C:\Documents and Settings\<User>\NTUser.dat. Note that it is a hidden system file.

I do not have the time to create an entire report, but here is how to export the printers for all of the users. This will loop through every user directory, load their registry hive, and export the printers to a user directory at the base of the drive.

@echo off
pushd "C:\Documments and Settings\"
for /d %%A in (*) do call :ExportPrinters "%%~dpnA" "%~d0\%%~nA"
goto End

:ExportPrinters <UserDir> <Target>
set "xUserDir=%~1"
set "xTarget=%~2"
if not defined xUserDir goto :eof
if not exist "%xUserDir%" goto :eof
if not defined xTarget goto :eof
if not exist "%xTarget%" goto :eof
reg load "HKU\TempHive" "%xUserDir%\NTUser.dat"
reg export "HKU\TempHive\Printers\Connections" "%xTarget%\printers.reg"
reg unload "HKU\TempHive"
goto :eof

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .