Registry access

  • Thread starter Thread starter Steven Blair
  • Start date Start date
S

Steven Blair

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
 
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
 
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
 
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
 
In addition to what dlgproc said, your should only ever write in the
SOFTWARE folders, never in SYSTEM.
 
Back
Top