Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Registry for settings

Status
Not open for further replies.

c567591

MIS
Aug 12, 2002
67
US
I need to use the registry to store settings for my software. The settings are setup in the installation program.

We have been using HKey_Local_Machine in the past, but when installing in a corporate environment where the user does not have admin rights to the machine, we get errors writing to it.

If I use HKey_Current_User, then it will work ok, but if a different user logs in, then the registry settings are not there for them.
How can I do this without having to reinstall for every user. Or at least having to import regisrty settings for every user?

We can't assume an admin can be available to install all the time.

I've tried google searches but get overwealmed by too many sites that don't have info on what I am trying to do. Way too many sites talking about the registry...

What are my options here?
 
There are a couple of options:

(1) If the installing user has admin rights, then in your installer, grant all users permissions on the HKLM key so that they can write to it (using the RegSetKeySecurity Windows API function). You can also use regedt32 to set permissions.

(2) Use a configuration file, such as an INI file, instead of the registry.
 
The installing user cannot be assumed to have admin rights.

I would go the INI route, but the code is well established and I am trying to fix what we have. I can't afford to rewrite major portions like that. I have inherited this code and so I have to make do.

The HKLM to HKCU change was an easy search/replace in files.

Let me explain a bit better maybe:
If user Fred installs and the installer uses HKCU, then user Bob on the same machine would have to reinstall to have those registry settings.

Is there a HKey_ of some type that can affect all users of the same machine that can be written to without admin rights?
 
I don't know of any keys anywhere other than in HKCU that have write permissions for ordinary users by default. The only way to change that is to have an admin user set up a key under HKLM with full permissions. If you can't do that then you're stuck as far as the registry is concerned.
 
There is a Default User Key under HKEY_USERS\\.DEFAULT, not sure if this is accessible or not, but might be worth an attempt.

"Time Is Precious, Waste It Wisely
 
yur corporate environment is very lakadaaisical
if they are allowing the user to install software.
in my company no one installs anything. this is
thanks to the goober that almost wiped out the system
by letting a virus into the corparate net.

only the IT dept installs software. the code to do the
registry thing should not be so involved that a talented
fellow like yourself could not do the ini thang in
a couple of days. probably less.

you could do both and do the lookup in the code for
either registry or ini and then decide which to use.
thatway you maintain some bacwards compatibilty.


TC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top