Click here to Skip to main content
15,895,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to get the installed folder when the user uninstalls the application through Add/Remove Programs.

VB
Application.StartupPath
and
VB
Application.ExecutablePath 


instead of installed folder it is showing windows folder.

how do i get the exact location of the installed folder.?
Posted
Updated 28-Jun-12 1:09am
v2
Comments
Dave Kreskowiak 26-Jun-12 8:13am    
First, where is this code going?? What application?? Is this a custom action inside your installer??
Kiran Susarla 27-Jun-12 3:49am    
Are you using Visual Studio setup and Deployment project to create the installer?

1 solution

Hi,
You need to find all installed app from "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall"

Here is the sample code-
C#
private string FindByDisplayName(RegistryKey parentKey, string name)
        {
            string[] nameList = parentKey.GetSubKeyNames();
            for (int i = 0; i < nameList.Length; i++)
            {
                RegistryKey regKey =  parentKey.OpenSubKey(nameList[i]);
                try
                {
                    if (regKey.GetValue("DisplayName").ToString() == name)
                    {
                        return regKey.GetValue("InstallLocation").ToString();
                    }
                }
                catch { }
            }
            return "";
        }

C#
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
string location = FindByDisplayName(regKey, "MSN");
MessageBox.Show(location);


This example will compare the DisplayName keyvalue to your input name, if it find the value, then return the InstallLocation key value.
 
Share this answer
 
Comments
oppai_kamu 2-Jul-12 7:36am    
Thank you for the answer i have tried the code but it is returning empty string.

so i have opened the registry and checked and the InstallLocation is empty. So i tried to set the value during installation using the following code.


Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
InstallDir = Me.Context.Parameters("dir")

Try
Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall",True)
regKey.SetValue("InstallLocation", InstallDir)
regKey.Close()

But it is not updating the value.

SK

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