Solved

Set registry settings as Admin so that users can access

Posted on 1998-04-29
4
678 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

786 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