PowerShell Application Deployment Toolkit (PSADT) is the premier solution for enterprises looking to standardize their software deployment process.
PSADT consists of a collection of scripts, functions, and PowerShell modules designed to simplify the deployment and configuration of software applications. It provides a powerful framework that enables precise control over the deployment process, including pre-installation, installation, post-installation and cleanup tasks.
One of PSADT’s main strengths is its flexibility. Allows administrators to customize deployment scripts according to specific application requirements and organizational policies. This flexibility ensures that each deployment is tailored to meet the unique needs of your environment.
Speaking of flexibility, let’s see how you can easily add ActiveSetup in your application by simply calling a function within PSADT.
What is active configuration?
Let’s assume that your application requires a file to be copied to the Program data file to work as expected.
The best approach is to add the file inside your application’s MSI package and copy it to the AppData folder during self-healing (self-repair). However, this requires that the application must have declared the file type shortcut(s) or link(s).
What if your app doesn’t have any shortcuts or file type link(s)? Or maybe it doesn’t come in MSI format and just doesn’t have the advertised shortcuts?
Active Setup offers a stable solution.
ActiveSetup is a mechanism within the Windows operating system that allows you to run commands or scripts once for each logged-on user. It is primarily used for configuring user-specific settings or performing actions that must be performed once for each user profile on a computer.
When a user logs in, Windows checks the ActiveSetup registry keys to determine if any tasks should be performed for that user. If it finds any, it executes the specified commands or scripts.
When using an active configuration, the following keys are compared:
- HKLM\Software\Microsoft\Active Setup\Installed Components\
- HKCU\Software\Microsoft\Active Setup\Installed Components\
If the HKCU registry entries are missing, or the version number of the HKCU is less than in HKLMthen the specified command line defined in StubPath the registry key is executed for the current user.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\<MyApp>] "StubPath"=<Active Setup command line>
Implementing ActiveSetup in your application using PSADT
Adding a few lines of code and writing the appropriate Active Setup registry keys is not rocket science.
However, PSADT is about standardizing the software deployment process.
So why go through the hassle when there is a specific function in PSADT designed just for this – Set-ActiveSetup? Just call him. Here’s how you do it:
Set-ActiveSetup -StubExePath " $envSystem32Directory\WindowsPowerShell\v1.0\powershell.exe" -Arguments "-file `"$envProgramFilesX86\MyApp\MyAppScript.ps1`"" -Description 'Applying MyApp settings' -Key
It’s that simple. The function has many other parameters that you can take advantage of when customizing Active Configuration for your application.
A key parameter is –PurgeActiveSetupKey. It not only removes the Active Setup entry from the HKLM registry hive, but also loads the HKCU registry code of each logged-in user to remove the Active Setup entry from there as well.
This way, you ensure that Active Setup will run again for any subsequent reinstallation of the application.
Sign in/log in?
As mentioned earlier, the Active Setup command or script is run during user login.
This means that the user logged in during application installation must log out and then log in to run the Active Setup command or script.
What if I told you that PSADT fits this scenario as well? It includes a built-in feature that allows you to run a process with a registered user account. So basically, you can run the Active Setup command/script as a logged in user during installation.
All you have to do is call the Execute-ProcessAsUser function and it should look like this:
Execute-ProcessAsUser -Path "$PSHOME\powershell.exe" -Parameters "-Command & { & `"`"`"$envProgramFilesX86\MyApp\MyAppScript.ps1`"`"`"; Exit `$LastExitCode }" -Wait
CONCLUSION
The PowerShell Application Deployment Toolkit is an essential resource for IT professionals looking to standardization of software deployment processes across an organization.
Its comprehensive set of functions simplifies complex tasks and ensures that deployments are efficient and tailored to specific needs. By using PSADT, enterprises can achieve a higher level of accuracy and flexibility in their software deployment strategies.
Stay Ahead of the Curve
Don’t miss the latest tips, tools, and tactics in app packaging and deployment. Subscribe to our blog and get expert insights delivered straight to your inbox. Join our community of IT professionals today!
Register Now!