How to save registry key to a file

社会主义新天地 提交于 2019-12-10 23:15:06

问题


I am trying to save the registry key to file using the below API, but save failed.

String key = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\My App";
String fileName = "myapp.reg";
WinRegistry.saveKey(RegistryRoot.HKEY_LOCAL_MACHINE, key, fileName);

Registry key snippet

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\my app]
"DisplayName"="my app"
"DisplayIcon"="C:\\myapp\\.install4j\\installer.ico"
"UninstallString"="\"C:\\myapp\\uninstall.exe\""
"InstallLocation"="C:\myapp"
"DisplayVersion"="3.3.3"
"VersionMajor"=dword:00000003
"VersionMinor"=dword:00000003

Please help me.


回答1:


You need elevated privileges to do that. If you do this in a "Run script" action, set its "Action elevation type" property to "Elevate to maximum available privileges". A "Request privileges" action must have been executed successfully for that to have an effect.

To do this in any script wrap your code like this:

context.runElevated(new RemoteCallable() {
    public Serializable execute() {
        // run registry code here
        return null;
    }
}, true);


来源:https://stackoverflow.com/questions/41828316/how-to-save-registry-key-to-a-file

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