开发者

How to programatically get the list of installed programs

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


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;
            }
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜