0

I want to find the file path of a program installed on my computer. The following code is running to check if the program is installed. But when I want to read the InstallLocation in the registry, it returns an empty value.

Is there a situation that needs to be specifically specified while installing the program?

I tried the alternative ways here. The third answer shows the file path. But even if the program is removed, the answer still returns and it didn't seem like a healthy way.

Is there an alternative method to find the file path? If the problem is in the WixSetup installation, what is the point I need to fix? I can share the WixSetup codes as needed.

Note: I am using WixSetup for installation.

public static bool IsProgramInstalled(string programDisplayName)
    {
        foreach (var item in Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall").GetSubKeyNames())
        {

            object programName = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + item).GetValue("DisplayName");


            if (string.Equals(programName, programDisplayName))
            {
                string location = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + item).GetValue("InstallLocation").ToString();
                return true;
            }
        }

        return false;
    }
Ozgur Saklanmaz
  • 334
  • 1
  • 13
  • What program are you trying to detect? There's no requirement that a program will modify the registry while installing. – gunr2171 Mar 22 '22 at 12:01
  • Was application Published and installed using a setup.exe? When a program (executable) is just copied to a machine it is not installed. – jdweng Mar 22 '22 at 12:02
  • @gunr2171 I'm trying to find a program that I installed myself. My goal is to make a separate program that controls all my apps. From the main application it will be checked whether other programs are installed. If the program is not installed, it will provide information to the user to download and install. If it is installed, it will find the point where it is installed and run the application. – Ozgur Saklanmaz Mar 22 '22 at 12:05
  • @jdweng The setup file was created using the application WixSetup and installed through that setup file. – Ozgur Saklanmaz Mar 22 '22 at 12:07
  • See following : https://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/write_a_registry_entry.html?force_isolation=true – jdweng Mar 22 '22 at 12:14
  • @jdweng I looked at the place you posted and it seems to work. But I'm not sure where I should add it in the .wxs file. I see an error like; Component: 'RegistryEntries' does not belong to ant Feature. – Ozgur Saklanmaz Mar 22 '22 at 12:25
  • I solved the problem I stated. I added it to the WixSetup setup, but nothing changed. But you showed a way that shows the root of the problem. Thank you. – Ozgur Saklanmaz Mar 22 '22 at 12:36
  • @jdweng If I want to change something in the registry during installation, I can do as in the link you specified. But I couldn't find how I can write the file installation path in this field. – Ozgur Saklanmaz Mar 22 '22 at 12:45
  • Change following (see link above) : The registry item is TARGETDIR so the value is where the application is installed. – jdweng Mar 22 '22 at 12:51
  • When I do as you mentioned, Name : (Default) Type: REG_SZ Value: Default Value is written in the relevant field. Unfortunately it does not show the file path. – Ozgur Saklanmaz Mar 22 '22 at 13:18

0 Answers0