By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

Registry access

P: n/a
Hi,

My C# app uses the registry for storing DB params, but under Windows XP
SP2, a normal user cannot write to this key (a .NET exception is thrown
when the app is run, but only under this OS).
My question is, can a certain area of the registry get accessed by
normal users. The key I am currently using is:

SYSTEM\CurrentControlSet\Services\

Any help on this would be appreciated. I have already suggested that the
customer enable this key for access by the normal user, but that has not
been accepted :|

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
hi,

can you post some code to write values int the regestry.
I'm intrested in this, i would like my program to startup when windows is
started

thanks Maarten

"Steven Blair" <st**********@btinternet.com> schreef in bericht
news:uQ**************@TK2MSFTNGP15.phx.gbl...
Hi,

My C# app uses the registry for storing DB params, but under Windows XP
SP2, a normal user cannot write to this key (a .NET exception is thrown
when the app is run, but only under this OS).
My question is, can a certain area of the registry get accessed by
normal users. The key I am currently using is:

SYSTEM\CurrentControlSet\Services\

Any help on this would be appreciated. I have already suggested that the
customer enable this key for access by the normal user, but that has not
been accepted :|

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

P: n/a
Hi,

You want to see my registry code?

If so, here it is:

private static string REGISTRY_PATH =
@"SYSTEM\CurrentControlSet\Services\MyKey";

RegistryKey hklm = Registry.LocalMachine;
RegistryKey MyKey;

MyKey= hklm.OpenSubKey(REGISTRY_PATH,true);

MyKey.SetValue("DBName",m_DBName);

MyKey.Close();

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

P: n/a
Thanks
I'll try it out

regards Maarten

"Steven Blair" <st**********@btinternet.com> schreef in bericht
news:eJ**************@TK2MSFTNGP09.phx.gbl...
Hi,

You want to see my registry code?

If so, here it is:

private static string REGISTRY_PATH =
@"SYSTEM\CurrentControlSet\Services\MyKey";

RegistryKey hklm = Registry.LocalMachine;
RegistryKey MyKey;

MyKey= hklm.OpenSubKey(REGISTRY_PATH,true);

MyKey.SetValue("DBName",m_DBName);

MyKey.Close();

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #5

P: n/a
In Windows 2000 and XP certain keys can only be written to if your code is
running with Administrator privileges. For example, HKEY_LOCAL_MACHINE. The
HKEY_CURRENT_USER key, however does not require Administrator privileges. You
may want to change your code to write your software preferences to something
like:
HKEY_CURRENT_USER\Software\<CompanyName>\<Product> Settings

One thing to be aware of, keys written to the HKEY_CURRENT_USER key are
bound to a user, so if one user logs in, runs your software that writes
settings to this key, logs out, and then another user logs in, those settings
are tied to the other user and will not be there for the new user. This may
be desirable depending on your situation.

My rule of thumb is, write static software settings that will not change
after your software has been installed in
HKEY_LOCAL_MACHINE\Software\<Company Name>\<Product>\Settings
Typically, an Admin will be installing the software and thus, your software
will be running with Admin privileges and your software will be able to write
to this key.

Write user preferences in
HKEY_CURRENT_USER\Software\<Company Name>\<Product>\Settings

Anything else, write in a config file.

It’s considered bad to make your users run your software all the time as
Admin since this fails the security rule of running with the least privileges
as possible.

Hope this helps.
Regards
"Steven Blair" wrote:
Hi,

My C# app uses the registry for storing DB params, but under Windows XP
SP2, a normal user cannot write to this key (a .NET exception is thrown
when the app is run, but only under this OS).
My question is, can a certain area of the registry get accessed by
normal users. The key I am currently using is:

SYSTEM\CurrentControlSet\Services\

Any help on this would be appreciated. I have already suggested that the
customer enable this key for access by the normal user, but that has not
been accepted :|

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #6

P: n/a
In addition to what dlgproc said, your should only ever write in the
SOFTWARE folders, never in SYSTEM.

"Steven Blair" <st**********@btinternet.com> wrote in message
news:uQ**************@TK2MSFTNGP15.phx.gbl...
Hi,

My C# app uses the registry for storing DB params, but under Windows XP
SP2, a normal user cannot write to this key (a .NET exception is thrown
when the app is run, but only under this OS).
My question is, can a certain area of the registry get accessed by
normal users. The key I am currently using is:

SYSTEM\CurrentControlSet\Services\

Any help on this would be appreciated. I have already suggested that the
customer enable this key for access by the normal user, but that has not
been accepted :|

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.