Cannot read config data from HKEY_LOCAL_MACHINE on Vista

空扰寡人 提交于 2019-12-08 02:18:38

问题


We have a Java Web Start application and are trying to store application configuration data using HKEY_LOCAL_MACHINE instead of HKEY_CURRENT_USER. We can get someone with admin rights to launch the app the first time and set the configuration, so that it will store the values in the registry successfully. Nevertheless, subsequent Vista users without admin privileges cannot seem to even read the values from the registry in HKEY_LOCAL_MACHINE.

Perhaps our approach is incorrect, and there is a better way to store application configuration data. Can anyone help?


回答1:


Your program is likely being affected by registry virtualization.

If a 32-bit program attempts to write to the registry under HKLM\SOFTWARE and the permissions do not allow the write to succeed, then Virtualization kicks in. The program is told that the write was successful, and the data is actually written into HKCU\Software\Classes\VirtualStore\MACHINE\SOFTWARE. Then, when a 32-bit program attempts to read from the registry, values from the VirtualStore folder are returned to the program. This way, the program is tricked into thinking it successfully wrote to a location that it does not have permissions for, and 32-bit programs continue to work under Vista / Windows 7 without changes.

Also, due to UAC, an admin user will be treated as if he was a non-admin user, unless the program in question is specifically launched to run with admin privileges. Installer programs must run with admin privileges so that they can write to the HKLM area.




回答2:


You normally use java.util.Preferences to store application specific data on the client machine. On Windows machines this will behind the scenes be written into the Windows registry. Here's a Sun tutorial/guide and a more technical article about the subject.

If you'd like to get more access to the Windows registry, then you may find the jRegistryKey API useful, but this would of course work only when the webstart application is executed on Windows machines and not on Linux/Mac/etc. The java.util.Preferences API is more abstract in that.




回答3:


I may be wrong, but non admin users don't have access to HKLM period. Read or write.

If possible, store your settings in HKCU. Have the app contain default settings and if the HKCU values are not found, then the defaults are used and stored in the registry. The user should then have the ability to change those values.



来源:https://stackoverflow.com/questions/2691433/cannot-read-config-data-from-hkey-local-machine-on-vista

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