Read Registry Key Values on Windows 7
Posted on 2009-12-30
I have a VB.NET app that has been working fine on Windows XP Pro. Within the app, it initializes a variable as follows:
Dim strPath As String = My.Computer.Registry.LocalMachine.OpenSubKey("Software", True).OpenSubKey("Microsoft", True).OpenSubKey(".NETFramework", True).GetValue("InstallRoot")
I deployed the application to a Windows 7 machine and when the app attempts to initialize the above variable, it encounters the following run-time error:
Object reference not set to an instance of an object.
I am logged into the Windows 7 machine with a user account that is a member of the local Admins group. I have verified that the registry key and value exist on the Windows 7 machine. I have also verified that the local Administrators group and the Users group have at least Read permission to this registry key. On Windows 7, if you click Start, type in Regedit.exe, and press Enter, you then have to click Yes or No on the Warning dialog before you can enter the Registry Editor. Thinking that this Warning may somehow be the cause of my error, I disabled the warning, and Windows 7 prompted me to reboot in order for the change to be applied. After the reboot, however, the application still encounters the error listed above.
I do not understand why this error is occurring.