After switching the logged on user on a Windows Service, I found out that the original user had some printers set up that were not present in the new user’s profile.
While I could have manually set up the necessary printers on the new user, it seemed that there must be a way to do this that would ensure that all of the printers were set up correctly on the new user.
Printer information for each user is stored in the HKEY_CURRENT_USER\Printers registry key.
However, the HKEY_CURRENT_USER hive only shows registry information for whatever user you’re logged on as. What if you wanted to copy from one user (other than you), to some other user?
The HKEY_CURRENT_USER key for each user is found in the registry under the HKEY_USERS hive, under each user’s SID. If you don’t have an easy way to find out what a user’s SID is, what then?
There is a solution! The information that is displayed in the HKEY_CURRENT_USER hive is stored in the NTUSER.DAT file in each user’s profile.
Each user’s hive can be loaded either from the Registry Editor or the command line. Both of these must be started as an Administrator to have the privileges to do this.
The example below shows how to do this from a command line. If the user whose hive to be copied is called OLDUSER, the following command (reg load) should attach the OLDUSER hive as HKEY_USERS\OLDUSER. This can be run from Command Prompt or PowerShell.
reg load C:\Users\OLDUSER\NTUSER.DAT
Do the same thing with the new user (NEWUSER):
reg load C:\Users\NEWUSER\NTUSER.DAT
Note: If either of these users is currently logged on or running a service, they must first be logged off or the service stopped.
In the Registry Editor, export (in this case) the Printers key from HKEY_USERS\OLDUSER into a .reg file.
Open the .reg file with an editor and replace all instances of OLDUSER with NEWUSER. Save the file. Execute the file by double-clicking on it. Confirm the dialog box to add the information to NEWUSER’s hive.
To unload both users’ hives, execute the following commands:
reg unload OLDUSER
reg unload NEWUSER
(Remember to restart any Services that were stopped before loading!)
To verify that the information was copied correctly, you can log on as the new user and examine its HKEY_CURRENT_USER hive.