How to programmatically get a list of installed programs

I create a program that first checks whether a certain program has been installed or not, if it is installed, it continues to execute different code, if it is not installed, then it installs the application, and then proceeds to execute another code.

How do I programmatically check in VC ++ that an application is installed or not

+3
source share
1 answer

I have a C # function that does something similar, it looks at both 32-bit and 64-bit registry entries. I assume that you got the correct name of the program you are looking for, all you need to do is map it to the "DisplayName" key. I doubt you will have problems with C ++ ... It will look like this

     string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
     bool found = false;
     RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey);

     foreach (string skName in rk.GetSubKeyNames())
     {
        RegistryKey sk = rk.OpenSubKey(skName);

        if (sk.GetValue("DisplayName") != null && 
        sk.GetValue("DisplayName").ToString().Equals("WhateverProgramYouAreLookingFor"))
       {
        //whatever you need to do with it
        found = true;
        break;
        }
     }
    if(!found)
    {
        SoftwareKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
        foreach (string skName in rk.GetSubKeyNames())
        {
            RegistryKey sk = rk.OpenSubKey(skName);
            if (sk.GetValue("DisplayName") != null && 
            sk.GetValue("DisplayName").ToString().Equals("WhateverProgramYouAreLookingFor"))
            {
                //whatever you need to do with it
                found = true;
                break;
            }
        }
    }
+2
source

Source: https://habr.com/ru/post/1746171/


All Articles