2

I have created a small vb6 application which edits the registry in HKLM hive. It makes use of function RegSetValueEx. But when run the exe file in windows 7 and windows 8 pc it does not edit the registry even if run it in administrator user.

In windows XP it works fine.If i run same application as "run as administrator"(by right clicking exe and then run as) in windows 7 and 8 then it works properly.I think the windows 7 and 8 id designed to work like this only. But is there any method i can edit it without running as administrator? Or is there any code in vb6 which does the same.

Here is my small code

Important: When checking the code create exe and then run the exe and click on button(HKEY_LOCAL_MACHINE\SOFTWARE\Demo registry gets added in wow32 node because vb6 is a 32 bit appliaction).Running the code directly by opening code allows the registry to change.But creating the exe and then running it gives the problem which is the real time scenario in any application.

2 Answers 2

6

Microsoft has been warning developers since Windows 2000 that access to the HKLM branch of the registry should not be performed as normal user, as it will sooner or later be restricted to administrators. They also said you should not write to Program Files.

They didn't enforce that rule until Windows Vista, so nobody felt the need to change anything.

Now you have it: don't write to HKLM as normal user - it doesn't work. Don't write your settings to Program Files. It doesn't work.

Application run by the normal user may write their data to user folders and user hives in the registry, nowhere else.

4
  • TIL Lazy application programmers were the cause of Vista's UAC debacle. Apr 17, 2013 at 21:12
  • ok i agree. But when i right click on any registry in regedit there is an option "permission" Here permission can be set for the registry(even for user group i can give full control). So what is the use of this permission if i cant edit it?
    – Navaneet
    Apr 18, 2013 at 5:37
  • If i set permission "Fullcontrol" for the registry to "Everyone" group then i can edit the registry value even without administrator permission.
    – Navaneet
    Apr 19, 2013 at 9:38
  • Right. That's the purpose of user rights. If I had the chance to do it right or shoot myself in the foot, I'd shoot myself in the foot as well. Apr 19, 2013 at 11:49
5

If your application's sole purpose is to write to that value in the HKLM hive then you will need to add a "requiresAdministrator` manifest to the executable, causing Windows to prompt the user for admin access every time it's run.

If this is a small part of a larger project, then you should use COM elevation or just run a small stub executable with the manifest above, allowing windows to only prompt when it's required.

If your application doesn't require admin access at all then you should stop it trying to write to admin restricted locations, and instead use the user's own HKCU hive.

5
  • Hi Deanna.. I have a doubt with an old thread which is relate to this question(please see stackoverflow.com/questions/14931692/…) where you have mentioned that "you can setup a particular key in HKLM with the right permissions to allow your non admin program to write to it" . Please see comment section in that thread. Can you please justify your answer? How it can be done?
    – Navaneet
    Apr 18, 2013 at 10:53
  • @Navaneet As I said on that post, I don't use NSIS so can't provide you an answer. I do however use Inno for which I gave you a method. Without changing the permisisons, you will need to elevate as in this answer.
    – Deanna
    Apr 18, 2013 at 11:07
  • So if i use Inno and set permission for registry by using it, then can i edit it without "run as administrator"?
    – Navaneet
    Apr 18, 2013 at 11:22
  • 1
    @Navaneet Yes, you will be able to write to it as any user that you give permission to write to it.
    – Deanna
    Apr 26, 2013 at 9:00
  • Yes,I was able to do it in NSIS using Access Control plugin.Thank you so much.
    – Navaneet
    Apr 26, 2013 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.