问题
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