Configure user specific settings after software installation in system context, without the need of a reboot

By | 20.06.2017

When you deploy applications that require user specific settings, for example config files located in %APPDATA%, or registry keys in the HKEY_CURRENT_USER hive, you will surely use Active Setup to make sure every user that logs in gets the settings.

But what’s with the user currently logged in while the installation runs? Prompting for a reboot feels a bit bad if it’s just because that one registry key has to be set. There are ways to configure user settings, even if the installation runs in system context.

Set registry keys for users:

What we need to do is to enumerate the sub keys of the HKEY_USERS hive, exclude the well known SID’s simply by key length and keys which end with “_Classes” and write the necessary keys and values to the registry.
Usually the filter will return 1 subkey of HKU. In case there are more user sessions available, or a user runs processes in a different users context, more than 1 subkey might be affected. But those users would get the settings anyway when they log in, since there is always an Active Setup configured.

Here’s the Powershell:


Create a config file in the users %APPDATA% directory:

If the applications configuration has to be done on file level, you can get the currently logged in user with a WMI query. Here’s a sample of how to create a folder in the currently logged in users AppData directory:

Be aware if you test while you are logged in via RDP, there is no user stored in the WMI.

Leave a Reply