Click here to Skip to main content
15,886,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

If the application is running and the user tries to uninstall the application then I want to prevent the uninstallation.


Help me out....
Posted
Updated 22-Dec-10 21:48pm
v2
Comments
Sandeep Mewara 23-Dec-10 1:08am    
via code you are asking? Not very clear of the case.
Sergey Alexandrovich Kryukov 23-Dec-10 1:15am    
Why do you think uninstallation can complete if the process is running? maybe some steps could be done but uninstallation will certainly fail to delete your code...

And, just in case, how about the opposite approach -- uninstaller asks if you "really-really" want to uninstall and terminate the process which prevents uninstallation? It may make sense...
subhash04573 23-Dec-10 1:22am    
while uninstalling, if the application running. u will get pop up dialog saying
the following app is opened
Cancel Retry Ignore.
If i selected ignore it's continue uninstall but the application which is opened is remained and then i have to close manually.

i can able to kill the process but i want to stop uninstallation.
Dalek Dave 23-Dec-10 3:49am    
Edited for Spelling and Syntax

1 solution

I would recommend creating a custom action in your setup project to override the OnBeforeUninstall() function, and cancel it in there. Something along these lines:
C#
protected override void OnBeforeUninstall(IDictionary savedState)
{
     base.OnBeforeUninstall(savedState);
     if(Process.GetProcessesByName("nameOfYourProcess").Length > 0)
     {
          throw new InstallException("Cannot uninstall while appname is running.");
     }
}
 
Share this answer
 
v2
Comments
subhash04573 23-Dec-10 2:11am    
Thank you very much.
can you explain what is it mean
Process.GetProcessesByName("nameOfYourProcess").Length > 0
JOAT-MON 23-Dec-10 2:21am    
Process.GetProcessByName() is a static function that will search the currently running process list for a process with the name you pass to it as a parameter. It returns an array of processes, so if that array is .Length == 0 then the process is not running. However, if the .Length > 0 then the process it was looking for is running.
subhash04573 23-Dec-10 5:34am    
Thank you very much.......
Toli Cuturicu 23-Dec-10 19:54pm    
That is not c# (read the question tags before answering)
JOAT-MON 24-Dec-10 5:35am    
@Toli - I did read, but it is my habit to do my custom actions in vb. Answer edited to show the C# translation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900