我正在尝试使用以下API将注册表项保存到文件,但是保存失败。

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


注册表项代码段

[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


请帮我。

最佳答案

您需要提升的权限才能做到这一点。如果在“运行脚本”操作中执行此操作,请将其“操作提升类型”属性设置为“提升到最大可用特权”。必须成功执行“请求特权”操作才能生效。

要在任何脚本中执行此操作,请像下面这样包装代码:

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

关于java - 如何将注册表项保存到文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41828316/

10-10 16:00