Check if application is installed in registry

前端 未结 7 603
庸人自扰
庸人自扰 2020-12-01 21:07

Right now I use this to list all the applications listed in the registry for 32bit & 64. I have seen the other examples of how to check if an application is installed wi

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 21:40

    Here is my version for 64 bits

      public static string[] checkInstalled(string findByName)
        {
            string[] info = new string[3];
    
            string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    
            //64 bits computer
            RegistryKey key64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            RegistryKey key = key64.OpenSubKey(registryKey);
    
            if (key != null)
            {
                foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
                {
                    string displayName = subkey.GetValue("DisplayName") as string;
                    if (displayName != null && displayName.Contains(findByName))
                    {
                        info[0] = displayName;
    
                        info[1] = subkey.GetValue("InstallLocation").ToString();
    
                        info[2] = subkey.GetValue("Version").ToString();
                    }
                }
    
                key.Close();
            }
    
            return info;
        }
    

    you can call this method like this

    string[] JavaVersion = Software.checkInstalled("Java(TM) SE Development Kit");
    

    if the array is empty means no installation found. if it is not empty it will give you the original name, relative path, and location which in most cases that is all we are looking to get.

提交回复
热议问题