application can't read string in registry

I am trying to read a connection string in the registry for my ASP.NET 4.0 web application.

I've created manually a key in the registry:


screenshot of registry entry
The name is ConnectionString, type REG_SZ and data is the connection string.

I set permissions on the registry for read access.

I've tried a few ways to read the key.

            Dim pRegKey As RegistryKey = Registry.LocalMachine
            pRegKey = pRegKey.OpenSubKey("SOFTWARE\\MyKey")
            Dim val As Object = pRegKey.GetValue("Setting")

            Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MyKey\\Setting", False)

I get pRegKey = Nothing and regKey = Nothing

What am I missing? How can I make this work.

Any help appreciated.

Who is Participating?
Paul MacDonaldDirector, Information SystemsCommented:
Make sure the ASP.Net process account (usually called "ASPNET") has access to that registry key.

Try reading another key, just to see if you can get anything returned.
Paul MacDonaldDirector, Information SystemsCommented:
You don't get an error, just nothing returned?

What .Net Framework are you using?

What user(s) have access to the Registry key?
scottydooAuthor Commented:
Hi Paul,

That's right. "Nothing" returned.

I use Visual Studio Express 2012
The app uses .NET 4.0
PC is Win 8.1


"CREATOR OWNER"  Special permissions
"SYSTEM" Full Control and Read
"Administrators" Full Control, Read, Special permissions
"Users" Read

Note that "CREATOR OWNER" it doesn't alow me to change it to "Read" or "Full Control".

Thanks, Paul.
Paul MacDonaldDirector, Information SystemsCommented:
So the problem is fixed?

Thanks for the points.
scottydooAuthor Commented:
Hi Paul, not really ... Couldn't find the process account. However, I managed to read a Microsoft key:

        Dim l_subKeyPath As String = "Software\Microsoft\Windows NT\CurrentVersion\Windows"
        Dim l_regKey = My.Computer.Registry.CurrentUser.OpenSubKey(l_subKeyPath)
        Dim deviceValue As String = l_regKey.GetValue("Device")

Open in new window

I am running out of time and I put code I think is correct and the people installing the app on the server can figure it out!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.