views:

130

answers:

1

Hi,

I am creating a program which first checks whether a particular program has been installed or not, if it's installed it continues to execute other code, if it's not installed then it installs the application and then proceeds to execute the other code.

How do i check programatically in VC++ that the application has been installed or not

+1  A: 

I got a C# function that does something similar, it looks on both the 32 bit and the 64 bit entries in the registry.I'm assuming you got the right name of the program you are looking for all you need is to match it with key "DisplayName". I doubt you'd have problems making it C++...It would go something 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;
            }
        }
    }
irco
I use this method too, but I also skip keys with parents (because they're service packs, system updates, etc.) and Office Multilingual (MUI) packs because they don't show in Add/Remove programs.
jeffm
oh thats a good idea, i was actually thinking of a way to skip those, how do you know if an entry has children?
irco