Solved

Set registry settings as Admin so that users can access

Posted on 1998-04-29
4
684 Views
Last Modified: 2008-02-01
When an Administrator installs my application I need to install the application's registry settings so that regular users can access the registry settings.

Currently the application's registry settings are in HKEY_CURRENT_USER. When the application is installed by the Administrator the settings are set correctly, BUT when the user logs in (s)/he cannot access the Administrator's HKEY_CURRENT_USER settings.

An alternative solution could be to use HKEY_LOCAL_MACHINE instead. However 'GetAppRegistryKey()' (in APPUI3.CPP in the MFC src) has HKEY_CURRENT_USER hardcoded in. 'GetAppRegistryKey()' is called by various functions in the MFC library. It is conceivably possible to write our own versions of 'GetAppRegistryKey()' and all the functions that call it, but this could be an ardous task, assuming that all the MFC calls to 'GetAppRegistryKey()' are provided in the source.

I am giving this question 75 points because I am assuming that there is standard (and relatively simple) way of dealing with this problem.
0
Comment
Question by:tconway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1167396
The GetAppRegistryKey() function is not virtual and there for cannot be overridden by your own function.

The best solution for your problem is to manipulate the registry your self. There is some classes for handling the registry on codeguru:

http://www.codeguru.com/misc/registry_ult.shtml
http://www.codeguru.com/misc/registry.shtml



0
 

Author Comment

by:tconway
ID: 1167397
This answer specifies wrappers I could use for the registry, but does not explain how I can prevent MFC classes from using HKEY_CURRENT_USER when I want to use HKEY_LOCAL_MACHINE.

For instance, CControlBarInfo::SaveState() calls CWinApp::WriteProfileString() which in turn calls CWinApp::GetAppRegistryKey(). Therefore I cannot use a CDockState object if I want to use HKEY_LOCAL_MACHINE.

I would also be interested in a solution which allows me to put my settings in HKEY_CURRENT_USER as Administrator and also have those settings available to other users.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1167398
Ahhh..... OK, now I'm with you. I'll look into the problem.
0
 
LVL 1

Accepted Solution

by:
Arkadiy earned 100 total points
ID: 1167399
Here is a suggestion: on setup, write the profile to HKEY_LOCAL_MACHINE. Then, when you run as a user and HKEY_CURRENT_USER does not have the key you expect, copy it from HKEY_LOCAL_MACHINE. This way you have the best of both words. You  can use registry enumeration API so that the registry copying code does not have to know the exat key structure. As an additional benefit, plain users may HAVE to use HKEY_CURRENT_USER  because they do not have writing access to HKEY_LOCAL_MACHINE.
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question