tags:

views:

17

answers:

1

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!

A: 

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