I have an installer which installs a key on the HKEY_CURRENT_USER. When I run the installer, it only adds it on the user that is installing. Is there a way to add the key to all users at once?
Thanks
The HKEY_CURRENT_USER registry hive is specific to each user, so in order to modify this for another user, we first need to identify where that information is stored.
Open regedit and select HKEY_USERS then go to File->Load Hive. Browse to the users Hive file, usually NTUSER. DAT located at %userprofile%. This of course requires you to be admin or have access to the users hive file.
No, HKCU doesn't override HKLM. If you make a change in HKCU, it will be applied to the current user only. However, if you apply for a change in HKLM, it will apply to the entire computer.
You'd have to go through all the different users under HKEY_USERS
, which requires elevated rights. And doesn't capture any users that have not yet been created. That's just the wrong approach.
The way to do it is to add the default values to a corresponding key under HKLM
at install time. When your program attempts to read from the registry, it looks in HKCU
first, and if your key is not present, it copies the information from the corresponding key in HKLM
to the key in HKCU
.
A general rule of installer programs is that they should not rely on being run by the user that will subsequently use the program that has been installed. Certainly in corporate settings programs are usually installed under a user account that will never subsequently run the program being installed.
In some cases, Active Setup may be the solution.
It works by adding a key to HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\%package name% with a version number. When a user logs in Windows checks this location and compares it to HKCU\SOFTWARE\Microsoft\Active Setup\Installed Components\%package name%. If it is missing or a lower version then it runs whatever has been set in HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\%package name%\StubPath.
You can do some custom things this way, for example I used it to add a certain script (to map a network drive) to the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run the following way:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\MapDrive" /v "Version" /d "1" /t REG_SZ /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\MapDrive" /v "StubPath" /d "reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v "MountDrive" /d "C:\map.cmd" /t REG_DWORD /f" /f
What happens here:
Sounds complicated, but makes sense once you figure it out, and very useful.
http://wpkg.org/Adding_Registry_Settings#Adding_entries_to_HKCU_for_all_users
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With