As an IT Professional, I often come across applications that store their configuration settings in a file within the %APPDATA% folder.
If the application package comes in MSI format, there are two ways to handle the files in the %APPDATA% folder:
- Via Self-Repair (you just need to make sure your shortcuts are advertised)
- Via ActiveSetup (can be used if the application package doesn’t include any shortcuts)
- Via Custom Action
For more information on handling user resources in MSI, check out our article: “3 Ways of Handling User Resources in MSI: Self-Repair, Active-Setup, CustomAction”.
What if the application package doesn’t come in MSI format?
You still can handle the files in the %APPDATA% folder using ActiveSetup.
First, create a script that copies the required files to the corresponding location in %APPDATA% folder, and then configure the script to run at logon via ActiveSetup.
Manage the files in the %APPDATA% folder using PSADT
The PowerShell AppDeploy Toolkit (PSADT) tool is a versatile solution with many pre-built functions to help you streamline and standardize the deployment process.
Let’s walk through how to handle %APPDATA% files using PSADT.
Create the Script to Copy the File(s) to %APPDATA%
Start by creating a PowerShell script that copies the required file(s) to the corresponding location within the %APPDATA% folder. Your script should look like the one below:
If (!(Test-Path "$env:APPDATA\audacity\"))
{
New-Item -ItemType Directory -Path "$env:APPDATA\" -Name "audacity"
}
Set the Active Setup
Once the PowerShell script is created, configure the Active Setup registry key. In PSADT, it would look like this:
Set-ActiveSetup -StubExePath 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -Arguments "-file `"$envProgramFiles\Audacity\DisableAutoUpdate\DisableAutoUpdate.ps1`"" -Description 'Applying Audacity 3.5.1 settings' -Key 'AudacityTeam-Audacity-3.5.1-PR1.0'
Let’s break it down to understand the logic behind better:
The Set-ActiveSetup is the PSADT function which creates an Active Setup registry entry to execute an action for each user at logon.
It contains the following parameters:
- StubExePath – Path to the executable file that runs at user logon
- Arguments – Arguments passed to the executable (in this case, our PowerShell script)
- Description – Description of the Active Setup
- Key – The registry key name for the Active Setup entry
How Does the Active Setup Work?
Active Setup works by setting up a registry entry in the HKLM (HKEY_LOCAL_MACHINE) registry hive, which replicates itself to the HKCU (HKEY_CURRENT_USER) hive when a user logs in.
The process checks the “Version” value within the HKLM Active Setup registry entry against the version stored in the user’s HKCU. If the version in HKLM is newer, Active Setup recognizes that an update is required, and the file specified in the “StubPath” is executed for the user to apply the necessary changes.
The Set-ActiveSetup function in PSADT handles the following:
1. Creates Active Setup Registry Entries in HKLM:
The function generates registry entries under the path:
HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\$installName
The $installName is a unique identifier for the application. This entry stores information such as the component’s name, version, and the executable path needed to run the configuration script or executable.
2. Defines the StubPath Value
Depending on the file type specified in the $StubExePath parameter (e.g., .exe, .bat, or .cmd), the function sets the StubPath registry value accordingly. This ensures that Active Setup can execute the correct file or script type when it runs.
3. Handles Versioning for Reinstalls and Updates
The Version value is handled with a timestamp-based format (YYYYMMDDHHMMSS) for precise tracking of updates. This enables administrators to trigger re-installations or updates within the same day by incrementing the version number. Each time the version is updated in HKLM, it triggers Active Setup to re-run for each user, applying any new configurations.
4. Copies or Overwrites the StubPath File
If the referenced file in StubPath exists in the Files subdirectory of the script’s directory, the function copies or overwrites the file at the destination path specified by $StubExePath. This ensures that the latest version of the file is always available for Active Setup to execute.
5. Executes the StubPath File for the Current User
The Set-ActiveSetup PSADT function allows the StubPath file to be executed immediately for the currently logged-in user, applying the changes without requiring the user to log out and back in. This is particularly useful for ensuring immediate configuration updates when required.
Conclusion
This approach streamlines user-specific configurations and ensures changes are applied consistently across all user profiles. It minimizes manual intervention and avoids requiring users to repeatedly log in and out.
FAQs
How should I handle %APPDATA% files for MSI-based apps?
Use Self-Repair if shortcuts are advertised. If not, go with Active Setup. Custom Actions are another option for more complex scenarios.
What if the app isn’t MSI-based?
You can still use Active Setup. Just write a script to copy the needed files into %APPDATA% and trigger it at logon via the registry.
What does Set-ActiveSetup do in PSADT?
It creates a registry entry that runs a script or command for each user at login—ideal for applying user-specific settings.
Do users need to log out for it to work?
Not necessarily. PSADT can run the script immediately for the current user, so changes apply right away.