Uninstall per-user MSI from System Context/Account



For a while i had some issues in a infrastructure of many users installing per-user MSI’s. Problem is, when the same application is packaged and deployed in the infrastructure, this is done to be a per-machine installation and, it doesn’t update/remove the per-user MSI because you are executing the installation from a system context/account.

When an MSI is installed per-user, this is not registered on the machine (obviously), meaning that even if you are an administrator, you theoretically cannot uninstall it. I’ve seen many threads over the years with users trying to clean an infrastructure from such installations, but unfortunately with not so much success.

To better understand per-user vs per-machine installations check out this link or this one.

However, i have developed in C# a small executable that can help you run commands on the user from a system context/account.

I have added a video down below:


This scenario has been tested on a Windows 10 machine version 1903 with Psexec (psexec -s -i cmd).

You can pass any argument you wish to the UserUninstallFromSystem.exe, either an msiexec command, batch file, powershell file, etc. For example:


UserUninstallFromSystem.exe msiexec /x {ProductCode} /qb /l*v "%temp%\uninstall.log"

UserUninstallFromSystem.exe C:\Temp\Uninstall.bat

UserUninstallFromSystem.exe C:\Temp\Uninstall.ps1


Because of some limitations, this only uninstalls applications on the current logged in user, so if you have the same application on multiple users on the same computer, this will only uninstall it on the currently logged on one.

I am searching a way to execute the code without the user to be logged in, i think i’m close to achieve that, but for now i am happy with the results. In any infrastructure, most of the devices have one user, so from my point of view it still helps a lot.

Of course, there are other ways you can use to uninstall a user-based installation. In SCCM you can create an application, set the deployment to run as user, and place a script in the Uninstall Command Line (you can leave the Install Command Line blank, we won’t be using it). The uninstall command line can be anything you want, an msiexec uninstall command, or you can use the script i’ve designed to search for a MSI an uninstall it. Of course modify the script to search trought the HKCU. After that make the deployment as mandatory and set the action to Uninstall. Whenever a user logs in ,this will uninstall the desired user-installed app.


NOTE! This executable can only be run from a system account, for example psexec!

You also need at least .Net Framework 4.0 present on the machine.


Leave a comment

Your email address will not be published. Required fields are marked *

five × one =