If you frequent ITNinja, you'll find it not too uncommon a suggestion to "use Active Setup" to address a problem. Normally it is because a member is asking about how to change a HKCU value or delete a file from a user profile path. This article is intended to help explain such a recommendation by offering some detail on just what Active Setup is and how it works.

If you are familiar with the registry's RunOnce capability, you'll find Active Setup is indeed very similar in the functionality it provides. However, Active Setup is better for deployment purposes because you can see what has been executed by looking to the registry. RunOnce on the other hand, removes itself after it executes so there is no inherent record of it.

If you want to manipulate a user profile, you need a user to be logged in. As such a logon script is also a fine candidate for injecting changes to HKCU. Just add the change to the logon script and users will get the changes as they log in. But you don't want it to run every time they log in, so it's best to add a condition: if change 1 has not run, execute change 1. This same logic is essentially what Active Setup provides (outside of the logon script).

Obviously if you don't have a logon script, implementing one for a simple change would be undesirable. However, I think one of the best reasons to choose Active Setup over a logon script update is that you can keep your deployment related tasks in your deployment package. You can leverage Active Setup for user specific changes right within your MSI package, task sequence or deployment script so they don't become disconnected from the application deployment.

You've probably seen Active Setup in action before but may not have known it was "Active Setup". For instance, the first time you logged into Windows you may have seen a status window advising you it was "setting up personalized settings". Essentially, Active Setup is a mechanism to trigger one or more actions to be run once per user. Windows looks to the Active Setup area of the machine profile (HKLM) and sees if it matches the current user profile (HKCU) copy of the subkey, runs any jobs necessary and then makes HKLM and HKCU match (signifying jobs have run and not need to run again). To be specific…

The Windows logon process looks at all subkeys under:

HKEY_LOCAL_MACHINE\Software\Microsoft\Active Setup\Installed Components\[ID]

Where [ID] represents a unique name for the component. There are a couple values to understand under each:

  • (default)
    • The display name of the job
  • Version
    • Versions are checked for a match, which handy if you need to rerun a job or tweak one because you don’t have to come up with a new unique name for the job
  • StubPath
    • The command line to be executed for the job 

Windows checks for a match in the same path under the user profile at:

HKEY_CURRENT_USER\Software\Microsoft\Active Setup\Installed Components\[ID]

For each job not listed and matching in HKCU (meaning it has not been executed) the StubPath command is executed and the user profile is updated to match that of the machine path (signifying it has been executed and does not need to run again in the future).

To see this in action, fire up the registry editor and create the following:

HKEY_LOCAL_MACHINE\Software\Microsoft\Active Setup\Installed Components\Test

  • (default)
    • Active Setup Test
  • Version
    • 1
  • StubPath
    • Notepad.exe

Log out and back in again. Windows will see that your profile has not run "Test" yet and will execute "notepad.exe". If this were a simple command line, it may run so quick that you don't get to see it so by running notepad we essentially hold the job open until notepad is closed. As such, you’ll be able to see the "Personalized Settings" dialog stating it is running "Active Setup Test" (our friendly name for the job).

Visit the HKCU path at HKEY_CURRENT_USER\Software\Microsoft\Active Setup\Installed Components\ and you'll see that our "Test" job isn't listed yet. Close notepad to let the job complete, refresh the Registry Editor display and you’ll see it is now listed as expected. With those values present, Windows will know not to run the job again for your user profile.

Deleting the value from HKCU will cause it to run again, but if you want to run it again, the best way to go about it is to update its version value. The StubPath can be a command line or script changing or deleting whatever necessary, but keep in mind that like a logon script it runs with user credentials and so cannot manipulate HKLM or write to most areas outside of the profile so take care and use this strictly for user profile related changes (leaving application installation or larger changes to your application deployment mechanism).

I hope you find this helpful. To see other content tagged with "Active Setup", see its tag home page here: http://www.itninja.com/tag/active-setup