开发者

Problem with JNIRegistry

I am using JNI Registry API to access Windows registry. Here is my code:

import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;
import com.ice.jni.registry.RegistryValue;

public class JNIRegistryExample {

    public static void main(String[] args) {
        RegistryKey regkey = Registry.HKEY_LOCAL_MACHINE;
        RegistryKey key =Registry.openSubkey(regkey,"SOFTWARE\\SMS\\DHC",RegistryKey.ACCESS_READ);  
        System.out.println(key.getFullName());
    try {
        RegistryValue value = key.getValue("ProntoPort");
        String x = new String(value.getByteData());
        System.out.println(x);
        }
        catch(RegistryException ex) {
            ex.printStackTrace();
        }
    }
}

This code works just fine for some registry keys, but not for others. For example, it works good to HKLM\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\ProgramFilesDir, but for many others it does not. (The example in the code does 开发者_开发百科not work, and I am 100% sure that it exists in the registry, I can check it with the reg command).

Anyone?

Many thanks!


Try this ....

Registry reg = new Registry();
RegistryKey topKey = Registry.HKEY_CURRENT_USER;
RegistryKey rk = topKey.openSubKey("Software\\Sparx Systems\\EA400\\EA");
String path = rk.getStringValue("Install Path");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜