开发者

How to programatically get the list of installed programs

开发者 https://www.devze.com 2022-12-31 01:22 出处:网络
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

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

精彩评论

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