Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
How can i get the installation path of my application before uninstall it? I mean the time that the user select to uninstall the application.

I have create an Installer Class and use the following code in BeforeUninstall event to find application path but it returns a wrong path in Windows drive(C:\Windows\...):

C#
using Microsoft.Win32;

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Installer\Assemblies");
string regfilepath="";
if (key!=null)       // Make sure there are Assemblies
{
    foreach(string Keyname in key.GetSubKeyNames())
    {
        if (Keyname.IndexOf("YOUR_EXE_FILE.EXE")>0)
        {
    regfilepath=Keyname;
    break;
        }
   }
}
string fullpath="";
for (int a=0;a<regfilepath.Length;a++)
{
  if (regfilepath.IndexOf("|",a,1)>0)
   fullpath+="\\";
 else
  fullpath+=regfilepath.Substring(a,1);
}
Posted

1 solution

You can pass "[TARGETDIR]" in your CustomActionData property, then back in your code you can get the [TARGETDIR].
Just have look at below provided link. It will help you

http://msdn.microsoft.com/en-us/library/2w2fhwzz.aspx[^]
 
Share this answer
 
Comments
M_Mogharrabi 27-Feb-12 3:20am    
Thanks ChandraKantt for your immediate reply,
but how can i set CustomActionData property programmatically and also use it in beforeuninstall event?
Chandrakantt 27-Feb-12 3:33am    
Can you provide me little more information about the steps you are doing. I think you might have created a installer which calls the custom action. You can have a look on below provided link. It shows how to pass [TARGETDIR] into CustomActionData property and how to get it into your installer class.

http://www.simple-talk.com/dotnet/visual-studio/visual-studio-setup---projects-and-custom-actions/

If you have still any problem then please provide more little more information related to your steps, so that I can guide you easily
M_Mogharrabi 27-Feb-12 3:55am    
Thanks a lot,I have found the solution... It was too easier than i thought!!!?

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