Registry key not being read

H

Henry Fleming

I have an C# assembly that is supposed to read a registry key:

RegistryKey regCurrentUser = Registry.CurrentUser;
RegistryKey regSoftware = regCurrentUser.OpenSubKey("Software",true);
RegistryKey regFamily = regSoftware.OpenSubKey("MyCompany", true);
RegistryKey regApp = regFamily.OpenSubKey("MySystem", true);
RegistryKey regSet = regApp.OpenSubKey("Set0", true);
m_strDSN = (string) regSet.GetValue("DSN", m_strDSN);

The string value "DSN" exists under the registry key
\\HKEY_CURRENT_USER\Software\MyCompany\MySystem\Set0 and definitely
has a value.

This assembly is placed under the /bin subdirectory of my ASP.NET
application. The code executes under the Session_Start event in my
Global.aspx page.

Whenever I start my web application, it doesn't read the registry
setting for the DSN; it always thinks it is null.

I cannot figure out what is wrong. I stepped through the same code on
a different machine and it reads the DSN all right. Help?

Thanks.
 
J

Jediah L.

Granted I really haven't looked through your code to validate that it is
correct, based on your identify of your ASP.Net process (which you haven't
specified) - HKCU is probably not the place you want it - you'd probably
want it in HKLM - but then you'd also need to give the worker process
identity (by default ASPNET) access to the key.

When you step through the code through a debugger - "you" are the current
user - so things work out all right - but I don't believe the ASPNET process
logs on interactively to the machine while executing your web app - so
that's probably where your problem lay.


One tool that you might find useful is RegMon put out by SysInternals
(http://www.sysinternals.com) that tool can help you monitor the registry
and find out why registry calls are failing.


Good Luck!
 
G

Guest

What i can suggest you store the registry key in machine level and try. If
you store the key under current User that can not be read by worker process
account. Otherwise change the worker process account to your logged in
account in machine.config file.

Regards,
Govind
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top