Check if application is installed in registry

前端 未结 7 579
庸人自扰
庸人自扰 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:50

    This is a clean way to do this without that much code.

        private static bool IsSoftwareInstalled(string softwareName)
        {
            var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") ??
                      Registry.LocalMachine.OpenSubKey(
                          @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
    
            if (key == null)
                return false;
    
            return key.GetSubKeyNames()
                .Select(keyName => key.OpenSubKey(keyName))
                .Select(subkey => subkey.GetValue("DisplayName") as string)
                .Any(displayName => displayName != null && displayName.Contains(softwareName));
        }
    

    Call it with a if-statement:

    if (IsSoftwareInstalled("OpenSSL"))
    
    0 讨论(0)
提交回复
热议问题