Click here to Skip to main content
15,897,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have this code to check if .net installed , and it work very good

C#
string key;
bool data = false;

 try
            {
                key = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall").GetValue("50727").ToString();
            }
            catch (Exception)
            {
            }
data = (key == "50727-50727");
label1.text = "installed";



i tried to used same code with change the location for anothor apps but it faild

32bit system

C#
string key1;
bool data1 = false;


try
          {
              key1 = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Wow6432Node").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall").OpenSubKey("Mozilla Firefox 38.0.1 (x86 en-GB)").GetValue("DisplayName").ToString();
          }
          catch (Exception)
          {
          }

          data1 = (key1 == "Mozilla Firefox 38.0.1 (x86 en-GB)");

          label10.Text = "Mozilla Firefox - " + data1.ToString();



64bit system

C#
string key1;
 bool data1 = false;


 try
           {
               key1 = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall").OpenSubKey("Mozilla Firefox 38.0.1 (x86 en-GB)").GetValue("DisplayName").ToString();
           }
           catch (Exception)
           {
           }

           data1 = (key1 == "Mozilla Firefox 38.0.1 (x86 en-GB)");

           label10.Text = "Mozilla Firefox - " + data1.ToString();


any idea ?
Posted
Updated 3-Jun-15 18:34pm
v3

thanks for all , this solved my Q
Check if application is installed in registry


C#
public static bool checkInstalled (string c_name)
{
    string displayName;

    string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
    if (key != null)
    {
        foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
        {
            displayName = subkey.GetValue("DisplayName") as string;
            if (displayName != null && displayName.Contains(c_name))
            {
                return true;
            }
        }
        key.Close();
    }

    registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
    key = Registry.LocalMachine.OpenSubKey(registryKey);
    if (key != null)
    {
        foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
        {
            displayName = subkey.GetValue("DisplayName") as string;
            if (displayName != null && displayName.Contains(c_name))
            {
                return true;
            }
        }
        key.Close();
    }
    return false;
}





And I simply just call it using

SQL
if(checkInstalled("Application Name"))
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900