Updating User Registries
Keywords: Updating User Registries
Question:
My problem is that I need my winbatch setup program to write amongst other things a proxy server setting to a key under:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\.. etcThe problem is that I would also like to do this this for all existing users and new users. Then if they login the settings would be there for them too. However, it would seem that you can only write to the current user and not to all the SIDs under HKEY_USERS (if I could even see them) - is it possible to do this? In the meantime I am investigating using the run/runonce registry options but I don't really want to run a test program everytime a user logs in. Your advise and comments will be welcome. Many thanks.Answer:
- If you can locate the individual directory where each user's profile is stored (either a local profile or a roaming profile), you can load the NTUSER.DAT and NTUSER.DAT.LOG files into the existing registry, make the mods and then unload the files. Here's how it works:
For example, my laptop is not part of a domain so all of my profiles are local profiles for the 3 or 4 user accounts that I have created on the workstation. Under C:\WINNT\Profiles there is a subdirectory for each user profile. Within each of these subdirectories is a NTUSER.DAT file and a ntuser.dat.log file.
What you need to do is to the following, assuming that my profile is as follows:
MyProfile = "C:\WINNT\Profiles\choppc\NTUSER.DAT" RegLoadHive(@REGUSERS,"TEMPchoppc",MyProfile)Now, I can access my entire "HKCU" hive as a sub-branch of the registry under the HKU (@REGUSERS) hive when I look under the top-level registry key named "TEMPchoppc".Once I have made all of the desired changes, I then have to unload the hive file that I previously loaded. Do this as follows:
RegUnloadHive(@REGUSERS,"TEMPchoppc")You could just as easily use @REGMACHINE instead of @REGUSERS if you wanted to.You MUST make sure that the key name you specify with RegLoadHive() does NOT already exist or you may encounter an error while attempting to load the hive at the specified top level key.
Once you get the method working for a single user it is easy to set up a directory/file processing loop where you enumerate all of the profile directories and you then load/modify/unload the NTUSER.DAT file for each profile. Just make sure that you do NOT attempt to process the profile of the account that is currently logged on to the workstation since that user's NTUSER.DAT file is currently loaded under HKCU (@REGCURRENT).
I use this method on WinNT to make make changes to the "Default User" and the "All Users" profiles to disable the Internet Explorer Welcome/Tips screen so that it will not appear each time a new profile is created on the workstation.
On Win9x you don't have the option of loading a hive file. If user profiles are enabled then all the user profiles that are present on the machine are available under HKU (@REGUSERS). Please note that you can only update locally cached copies of roaming profiles if roaming profiles are enabled. When a roaming profile is used, it is copied from its network storage location when the user logs on to the workstation and then it gets copied back up to the network when the user logs off of the workstation sucessfully. This means that roaming profiles on Win9x machines cannot be directly manipulated if that user is not logged on to the workstation.
So in summary, do the following:
- Logon as an administrator who has rights to modify the registry under HKEY_LOCAL_MACHINE and who has rights to directly access other users' local profiles on the local WinNT system.
- Use RegCreateKey() to create some sort of temporary dummy key under @REGMACHINE.
- Use RegLoadHive() to load another user's hive file (NTUSER.DAT) from the user's profile directory (c:\winnt\profiles\
- Make all the desired changes under the hive that was loaded. Every registry key & value that would have been located under @REGCURRENT for the user whose profile you just "loaded" will now be available under @REGMACHINE\.
- When you are done use RegUnloadHive() to unload the hive file.
- Repeat as necessary until you have modified all of the user profiles on the local WinNT system. If roaming profiles are in use then you could have problems because you might update the server copy while the user is currently using the profile on a workstation.
If you update the NTUSER.DAT file in the "Default User" profile directory then all new user profiles created on the local WinNT system will inherit the settings in that profile's NTUSER.DAT file. This profile gets copied whenever a new profile gets created locally.
- If you're using a domain and all users who log on are running through a default logon script, you can simply add a
regedit /s x:\blahblah\desiredsettings.reg
- Hkey_Users\.default\
is the registry key on which all other profile keys for all users is built the First time they log in.. if you want global settings.. places your changes there :) for NT workstation... for IE.. the combination of .default and Hkey_LocalMachine\Software should do the trick..
Article ID: W14709Filename: Updating User Registries.txt