Writing to Registry

G

glenn

I am trying to write to the registry and the objects that are suppose to be
handling this function are not working. Here is what is happening.

I am issuing the following commands:
RegistryKey reg =
Registry.CurrentUser.OpenSubKey("Software\\mykey\\mysubkey\\Settings",
true);

reg.SetValue("DBPath", "c:\\temp");

when I execute these lines, the function does write to the registry,
however, it does not write to HKEY_Current_User. Its writing to HKEY_USER.
There are no entries at all in CurrentUser like the command suggests that
its writing to.

Can anyone help me with this as its been a real pain. I do this sort of
thing in Delphi everyday and have never had any problems. Can C# not work
with the registry?

Thanks,

glenn
 
B

Bruce Wood

I have similar code, and it works just fine. I assume that you've
checked that OpenSubKey isn't returning null... that the subkey is
already in the Registry? (Well, of course, otherwise the reg.SetValue()
would have failed with a NullReferenceException, wouldn't it? :)

I have no idea why it would put the values under the wrong subkey. As I
said, my version works just fine, and I'm not doing anything different
from what you're doing, other than a CreateSubKey if OpenSubKey returns
null.
 
W

Willy Denoyette [MVP]

glenn said:
I am trying to write to the registry and the objects that are suppose to be
handling this function are not working. Here is what is happening.

I am issuing the following commands:
RegistryKey reg =
Registry.CurrentUser.OpenSubKey("Software\\mykey\\mysubkey\\Settings",
true);

reg.SetValue("DBPath", "c:\\temp");

when I execute these lines, the function does write to the registry,
however, it does not write to HKEY_Current_User. Its writing to
HKEY_USER. There are no entries at all in CurrentUser like the command
suggests that its writing to.

Can anyone help me with this as its been a real pain. I do this sort of
thing in Delphi everyday and have never had any problems. Can C# not work
with the registry?

Thanks,

glenn

And who's the current user? What kind of application is this (windows
service, web, console ...)?

Willy.
 

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

Top