我正在使用JNI Registry API来访问Windows注册表。这是我的代码:
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();
}
}
}
此代码适用于某些注册表项,但不适用于其他注册表项。例如,它适用于HKLM \ SOFTWARE \ MICROSOFT \ WINDOWS \ CurrentVersion \ ProgramFilesDir,但对于许多其他人则不行。 (代码中的示例不起作用,我100%确定它存在于注册表中,我可以使用reg命令检查它。)
任何?
非常感谢!
答案 0 :(得分:0)
试试这个......
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");