如何将注册表项保存到文件 [英] How to save registry key to a file

查看:75
本文介绍了如何将注册表项保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

注册码片段

[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

请帮助我.

推荐答案

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

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);

这篇关于如何将注册表项保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆