Question

While unistalling the application normally if more than one user is logged in the system, it would show a message box

enter image description here

if the user hits continue, the uinstallation happens but might be with errors. I've a project installer, in which I want to end the installation process if more than one users are logged in. So I wrote this condition in the Before_UnInstall event:

if(Process.GetProcessesByName("explorer").Count()==1)
{
        //do uinstall
}

else
{
       //do not do unistall
}

My question was how do I stop the uninstall event from being fired, in the else part?

Possible Change

based on Alexey's answer I thought I would check the distinct owners of the process. I found how to find the owner of a process using WMI from here

Was it helpful?

Solution

You should not do it yourself: Windows Installer will take care of the files locked by other processes. Additionally, it is legitimate for a user to have several explorer processes, so your code will refuse to uninstall in such case, yet only one user is logged on. And I doubt you can detect processes from other users, unless you run this code elevated.

What you really want to check is whether the application you uninstall is running under any user account. If other users of the computer do not have your application running, it is usually safe to proceed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top