winman2004
11th March 2013 15:32 UTC
Reading registry from HKLM for any user
I am developing a software which has demo for limited days of 30 days.So my s/w on installation writes a registry to HKLM which is used by me to handle the demo version. Now the problem is in windows 7 and 8 user(without admin permission) cannot access HKLM.so my code in s/w fails to check registry in HKLM. In NSIS website i saw about access control plugin.Can it be used in my case so that in all users i can read registry from HKLM? (Note:My s/w is 32 bit)
Afrow UK
11th March 2013 17:55 UTC
You should be able to read from HKLM with no problems. Only writing will be an issue if you do not have administrator privileges. Are you sure it's not reading from the wrong key (e.g. being redirected to Wow6432Node on 64-bit Windows)?
Stu
winman2004
12th March 2013 14:11 UTC
Yes.Sorry for confusing question. I also want to write to that registry in HKLM for users also. Can i do it by using access control plugin? Or is there any option by which user can write to a particular registry in HKLM?
MSG
12th March 2013 14:34 UTC
Yes, you can grant all or specific users write access to a key in HKLM, using the accesscontrol plugin. This is however not the way you should do it. If an application is designed to be run by users, it should store its info in userlevel storage (registry or harddisk). This is how Windows is designed to work. If you're doing it differently, you're doing it wrong.
Possible solution:
Upon installation (admin level), write default settings to HKLM.
Upon running the application, make your application copy the defaults to HKCU. Then use that registry hive from that point on.
Upon uninstallation, either enumerate all HKU hives (using enumusersreg.nsh) to remove stray HKCU entries, or leave them behind.
winman2004
12th March 2013 15:35 UTC
My software has limited demo version for 30 days. And also there are some other conditions as some fetures can be used only 100 times etc. So in this case for the user also i want to update the registry of demo(a single registry) of my software in HKLM every time he uses it. I think doing this is not wrong. Also if i write this registry in HKCU separately then user can use my software with different users in his PC so he may cross the limit of using certain features of s/w. So i need to write it in HKLM.( I also know that the user may delete or change the registry and user has got full control of the s/w , but it is a different issue.).So i need to write registry to a HKLM (only a single registry which tracks demo limitation). Can i do it in NSIS using access control plugin or is there any other good methods to do the same?
MSG
12th March 2013 17:51 UTC
It is wrong to give all users write access to protected registry hives or protected folders. It is up to you to decide whether you're willing to break the rules, but your software IS badly written if it needs HKLM access for all users. There are plenty of other ways to accomplish what you want. You should probably be writing to a world-writable file in allusers appdata.