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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.