Registry: Allowing Access For All Users

ayozzhero

Well-known member
Joined
Apr 6, 2005
Messages
186
Location
Malaysia
Programming Experience
1-3
I developed an application that needs a user to log in as Administrator to install, since it will install MDAC and .Net Framework 1.1. Every time it runs, the app will check for registry under:
HKEY_LOCAL_MACHINE/Software/MyCompany/MyApp

On certain PC, users are not Admin. The problem is, if a user is not logged as Administrator, Windows disallow my application from accessing the registry unless Admin sets permission for the user to access (read/write) the registry.

My question is, is there anyway in VB which we can modify the registry permission for this specific registry folder only (HKEY_LOCAL_MACHINE/Software/MyCompany/MyApp). I mean, Admin runs the app for the first time, the app sets permission for the registry to be accessible for all users (or specific user). Hence, when the actual user runs it the next time with his/her own login, the application is able to access the registry.

Thank you for helping. Any idea is most welcome.
 
It sounds like you should be using HKEY_CURRENT_USER rather than HKEY_LOCAL_MACHINE. HKEY_CURRENT_USER is a virtual hive that replicates the current users data from HKEY_USERS.
 
ayozzhero said:
unless Admin sets permission for the user to access (read/write) the registry

Thanks for the reply, but that is what we currently do... for compatibility reason, I cannot do it as suggested by jmcilhinney yet... except for next app :)

What I meant was... if there is any way I can put a button in my apps, for example, where admin can press that button (in admin mode/login) and it sets 'Read/Write' for 'Everyone' for that specific registry branch.
 
If your app requires administrator priviliges then it should only be installed by an administrator, plain and simple. Lots of apps specify this very thing for this very reason. If you're having an administrator login through your app, which may or may not be possible, to change registry privileges than why doesn't the administrator just log in and install the app? Trying to circumvent security that has been implemented for good reasons is not a good idea.
 
Currently, the administrator installs the software. However user will run it with their own Windows login. Sorry for not being clear, but my situation is like this... there many administrators are administrators by title only. They don't even know how to set permissions for the registry... and if I am to make a user manual for that, I need to cover many versions of Windows.

Therefore, I wish if I could have a button in my app, when the administrator runs it for the first time, it sets 'read/write' permission for Everyone (just an example) to that specific registry folder.

Hence, when users themselves run the app next time with non-administrative login, they app is able to read/write to that registry.

Thanks for your help :)
 
What is your app reading/writing to the registry?
If it's app settings, the new 'standard' is to use configuration files stored either in the same directory as the app or in the users ApplicationData folder (which can be found using Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData). The data is usually stored in XML format.
Here are a couple links for using XML as a config file:
Saving and Retrieving Application Settings
Managing configuration settings persistence in .NET applications
 
Thanks Paszt,

The links simplified a lot of my work. I admit that there was a flaw in designing my current app and I will change that in the next version. For time being, I can just educate my users of how to modify the registry permission.
 
Back
Top