Solved

Set registry settings as Admin so that users can access

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now