michelepizzi

Check if application is installed in registry

Apr 6th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. public static bool checkInstalled (string c_name)
  2. {
  3.     string displayName;
  4.  
  5.     string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
  6.     RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
  7.     if (key != null)
  8.     {
  9.         foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
  10.         {
  11.             displayName = subkey.GetValue("DisplayName") as string;
  12.             if (displayName != null && displayName.Contains(c_name))
  13.             {
  14.                 return true;
  15.             }
  16.         }
  17.         key.Close();
  18.     }
  19.  
  20.     registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
  21.     key = Registry.LocalMachine.OpenSubKey(registryKey);
  22.     if (key != null)
  23.     {
  24.         foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
  25.         {
  26.             displayName = subkey.GetValue("DisplayName") as string;
  27.             if (displayName != null && displayName.Contains(c_name))
  28.             {
  29.                 return true;
  30.             }
  31.         }
  32.         key.Close();
  33.     }
  34.     return false;
  35. }
  36.  
  37. 'And I simply just call it using
  38.  
  39. if(checkInstalled("Application Name"))
Advertisement
Add Comment
Please, Sign In to add comment