Access to HKLM registry branch on Win 7 from within application

大城市里の小女人 提交于 2019-12-11 00:55:25

问题


Is it possible to write to the HKLM registry branch in Win 7 from an application?

My existing code is not able to write to the HKLM registry branch on Win 7 machines, while it is able to do this on XP machines.

How do you allow an application read/write access to HKLM on Win 7, or should all applications now just use HKCU instead? What if I need to store settings on a machine basis rather than a user basis?


回答1:


You need to decide whether you are writing an administrative app, that deliberately changes settings for all users (by writing to HKLM) or an ordinary app, that does not. If you really are writing an administrative app then put a manifest on it that has a requestedExecutionLevel of requireAdministrator. The user will get a UAC prompt every time they run the app, but your writes to HKLM will succeed. Alternatively, change the app to write to HKCU or some other per-user store.

(No idea how to add a manifest? Tell me what language/IDE you're using and I'll try to help.)

Relying on virtualization is a bad idea. It was implemented to let unmanifested applications at least sorta kinda work. It will go away some day and is not that great while it's here.




回答2:


Win 7 uses Registry Virtualization

Read the article and look into (HKEY_USERS\<User SID>_Classes\VirtualStore\Machine\Software).



来源:https://stackoverflow.com/questions/3146666/access-to-hklm-registry-branch-on-win-7-from-within-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!