Question : Read Registry Key Values on Windows 7

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.

Answer : Read Registry Key Values on Windows 7

The preference currently is to store settings in app.config, you can access them via My.Settings (http://msdn.microsoft.com/en-us/library/saa62613(VS.80).aspx).  Use per-user settings as much as possible.  If you choose to continue using the registry you should not have any issues writing to subkeys of Registry.CurrentUser (HKEY_CURRENT_USER).

Hmm, the debugger should run correctly even when stepping through code on VS 2005 or 2008, must be something else causing your exceptions.

http://richnewman.wordpress.com/2009/06/06/running-visual-studio-as-an-administrator-under-windows-vista/
http://msdn.microsoft.com/en-us/vstudio/aa972193.aspx
Random Solutions  
 
programming4us programming4us