Build an MSI that installs per-user or per-machine
Throughout their entire history, MSI applications have used Microsoft Windows Installer as an installation and configuration tool provided with Windows since version 2.0 for Windows XP and proceeding to version 5.0 for Windows 7, 10, and 11.
Windows Installer 5.0 is already present as a component of the OS.
Windows Installer version 5.0 allows us to perform many operations that were not available in previous versions.
Some of them include:
- Authoring a package to secure new accounts, Windows Services, files, folders, and registry keys
- Enumerating all components installed on the computer and obtaining the key path for the component.
- Customizing the services on a computer.
Another key feature related to this article's topic is the possibility to develop single installation packages capable of installing an application in both a per-machine or per-user installation context.
What is an installation context?
An installation context dictates the circumstances and environment in which an MSI is executed and which resources are accessed. When it comes to the installation context of an application, there are two options:
1. Install in user context (“per-user” installation) - the currently logged-in user executes the setup, and the application is installed and available for that particular user’s profile.
2. Install in system context (“per-machine” installation) - the setup is executed by the “system” with system privileges, and the application is available for all users on that machine.
The "user context" installation is commonly used by a regular user with no admin privileges.While “per-machine” is the preferred method in enterprise environments and requires elevated privileges to install.
How do you know if an MSI is installing in a per-machine context?
One indicator that your MSI is installing in a per-machine environment is that the property ALLUSERS is set to 1 (check the property table).
Another indicator of a per-machine installation is the install location once the installation is finished. Usually, a per-machine application gets installed in C:\Program Files or C:\Program Files x86, depending on the application's architecture.
What happens if you try to run an MSI package as a standard user with non-administrative privileges?
In that case, the installation will fail because it tries to access resources and execute operations that a standard user account will not have permission to perform.
Below, you can see an example of an application installed per-machine.
How do you know if an MSI is installing in a per-user context?
The attribute ALLUSERS being set to 2 indicates that your MSI is installing in a per-machine environment (check the property table).
Compared to per-machine installations, a per-user application gets installed in a user profile location, usually in AppData\Local or AppData\Roaming.
Since it accesses user resources, a non-admin user can also install the application. You can see an example of an application installed per-user in the image below.
Installing your MSI on Windows 10
Windows Installer version 5.0, which was released with Windows 7, introduced the option to create a dynamic MSI. A dynamic MSI means that you can switch between per-user or per-machine at install time.
If you are using Advanced Installer to create your MSI packages, you might notice the option for the dynamic MSI which is listed in addition to the other three options.
After selecting the Per-machine if user is administrator, per-user otherwise install type; the program automatically adds the InstallTypeDlg dialog if it's not already present. If the user changes the combo box selection to another option, the InstallTypeDlg gets removed.
The Init Events from InstallTypeDlg are used to set the AI_DETECTED_ADMIN_USER property instead of the ALLUSERS property.
If you want to perform a per-user installation, the MSIINSTALLPERUSER property needs to be set to "1" when installing the MSI package from the command line .
To learn more about InstallTypeDlg, check out this article on How do I make the package install per-user or per-machine?
Per-User vs. Per-Machine Installations
Per User and Per-Machine installations have their advantages and disadvantages, depending on the environment and the purpose of the application.
Per-User vs. Per-Machine Installations Advantages
Per-Machine installation is the preferred way in an enterprise environment. This is mainly because it gives the option IT administrators who manage the infrastructure, to use configuration management tools and deploy applications without the need for user interaction.
A per-user install application is the preferred method in case of a shared device. You don’t want to populate other users' profiles with your application.
Per-User vs. Per-Machine Installations Disadvantages
Per-machine deployment is the primary deployment method in configuration management tools.
Custom actions in per-user MSIs could have problems. Most problems are related to accessing resources and not having the right permissions.
An update of an application might fail if you had a previous version of the application installed per-user and the new version is deployed via configuration management tool per-machine. This is because of the install location and how the app is registered. An application deployed via a configuration management tool is
Why MSIX Packages Install only per-user
As the latest application package format, Microsoft released MSIX. This format changes the install context because MSIX applications are installed only per-user even though the install location is under the %ProgramFiles%\WindowsApps folder.
Under an account, every user will see only the apps registered to their credentials. Also, if more users install the same app version on the device, the application is not downloaded or installed twice. This way, the OS reduces disk waste and bandwidth usage when updating the app.
Read more about MSIX in our MSIX Introduction guide.
Conclusion
I hope this article gave you a better understanding of per-user and per-machine installation contexts, as well as when and why to use each of them.
Let us know in the comments below if you have any questions or suggestions for topics you'd like us to cover.
Subscribe to Our Newsletter
Sign up for free and be the first to receive the latest news, videos, exclusive How-Tos, and guides from Advanced Installer.