简体   繁体   English

有谁知道如何使用 JNI-Registry (com.ice.jni.registry) 为密钥设置默认注册表值?

[英]Does anyone know how to set the default registry value for a key using JNI-Registry (com.ice.jni.registry)?

I'm currently trying to query and set some windows registry entries through a Java app.我目前正在尝试通过 Java 应用程序查询和设置一些 Windows 注册表项。 We are mandated to use the JNI-Registry library (for licensing reasons).我们被要求使用 JNI-Registry 库(出于许可原因)。 The keys and values to set are not under my control (I'm modifying values set by another, 3rd party, application).要设置的键和值不受我的控制(我正在修改由另一个第 3 方应用程序设置的值)。

I can get and set the various entries and values OK for normal keys and values, and I can query the default value for a key OK.我可以获取和设置普通键和值的各种条目和值 OK,我可以查询键 OK 的默认值。 However, I need to know how to set the default values for a key.但是,我需要知道如何设置键的默认值。

//This works
final RegistryKey regKey = Registry.HKEY_LOCAL_MACHINE.openSubKey("SOFTWARE\\company\\app\\subkey", RegistryKey.ACCESS_ALL);
RegStringValue blah = (RegStringValue) regKey.getValue("blah");
if (blah == null) {
    blah = new RegStringValue(regKey, "blah");
}
blah.setData("Some data");
regKey.setValue(blah);

//Not sure about this...
final RegistryKey regKey = Registry.HKEY_LOCAL_MACHINE.openSubKey("SOFTWARE\\company\\app\\subkey", RegistryKey.ACCESS_ALL);
String defaultValue = regKey.getDefaultValue();    //Gets the default value OK
//How do I reset it, though???
//need something like:
//   regKey.setDefaultValue("Some new value");

//The following does not seem to work
RegDWordValue defVal = (RegDWordValue) regKey.getValue(""); //Also tried ...getValue("Default")
defVal.setData("Some new Value");
regKey.setValue(defVal);

regKey.closeKey();

Does anyone know if this is possible?有谁知道这是否可能?

Yes, its possible.是的,这是可能的。

Well, in c#, for any key, you can do好吧,在 c# 中,对于任何键,您都可以

key.SetValue("", "value");

The nameless key is the default one.无名键是默认键。

This is documented at: http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.setvalue.aspx (page archived here )这记录在: http : //msdn.microsoft.com/en-us/library/microsoft.win32.registry.setvalue.aspx (页面存档在这里

Kinda late, i know.有点晚了,我知道。 still, hope it helps someone.仍然,希望它可以帮助某人。 I was looking for the same thing.我正在寻找同样的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM