-
January 4th, 2011, 11:04 PM
#1
Object reference not set to an instance of an object.
Hi, im new to c# and new to this forum.
Win 7 64bit
.net 3.5 (using vs2008)
I found this code online to get the 'UninstallString' from a specific subkey within the registry. I am trying to debug the code but im getting the 'Object reference not set to an instance of an object.' error.
I broke down the code in order to find where it was giving me the error and its at the point where the code posted below has *** ***.
Im not really sure how to fix this. I previously put a try and catch but it would still break the program. Any help on this would be appreciated.
Code Below:
String AppName = "Abode AIR";
RegistryKey ReadReg = Registry.LocalMachine
.OpenSubKey("SOFTWARE")
.OpenSubKey("Microsoft")
.OpenSubKey("Windows")
.OpenSubKey("CurrentVersion")
.OpenSubKey("Installer")
.OpenSubKey("UserData")
.OpenSubKey("S-1-5-18")
.OpenSubKey("Products");
String[] SubNames = ReadReg.GetSubKeyNames();
Console.ReadLine(); //Dont mind this line
for (int i = 0; i < SubNames.Length; i++)
{
RegistryKey temp = ReadReg.OpenSubKey(SubNames[i])
.OpenSubKey("InstallProperties");
***if (temp.GetValue("DisplayName").ToString() == AppName)***
{
Console.WriteLine("Found it");
}
}
Thanks for your support
-
January 5th, 2011, 01:20 AM
#2
Re: Object reference not set to an instance of an object.
Either temp is null or temp.GetValue("DisplayName") is returning null. You should be checking for null if it is a possible return value.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|