Reputation: 37
i have this code to check if .net installed , and it work very good
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
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
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 ?
Upvotes: 0
Views: 4276
Reputation: 8877
I would open regedit and navigate to that path.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall...
First, make sure that the name is there. If its not then that is the issue.
It could also be that the key you are looking for is going to look like HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{0B0BA4A44-B2AB-4B28-9A45-CBE2BFC5FFD1}
If this is the case then you would need to iterate through each item in Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall") and then look for the wanted DisplayName. (see Iterate through registry entries)
Just as a note, since you would be looking for "Mozilla Firefox 38.0.1 (x86 en-GB)" then if anything is not exact on another PC then it will not find it. Like if the version is 38.0.2 for example or if the browser is an EN version in the US. I would look at Mark Shevchenko comment for the best general checking. Using the uninstall path might not be that reliable.
By the way, There is a similar question here: Check if application is installed in registry
Hope this helps.
Upvotes: 1