tags:

views:

472

answers:

2

I want to create registry key through java program to add the jar file in the start up.

RegistryKey r=new RegistryKey(RootKey.HKEY_CURRENT_USER,"Software/Microsoft/Windows/CurrentVersion/Run");
        r.createSubkey("sample");

But i got the error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: ca.beq.util.win32.registry.RegistryKey.testInitialized()V
        at ca.beq.util.win32.registry.RegistryKey.testInitialized(Native Method)

How can i do that?
Thanks

+3  A: 

From the Javadoc:

Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.

You wouldn't be on a win 64 OS by any chance?

If not, the manual for jreg mentions:

jRegistryKey is a JNI library. To use jRegistryKey, the following files are required:

  • jRegistryKey.jar
  • jRegistryKey.dll

jRegistryKey.jar is the Java™ Archive (JAR) file containing the packaged Java™ class files, whereas jRegistryKey.dll is a Windows® dyanmically linked library (DLL) that contains the native (C/C++) code required to access the registry.

jRegistryKey.jar must be included in the CLASSPATH available to the Java™ Virtual Machine (JVM);

jRegistryKey.dll must be located in a directory included in the Windows® PATH environment variable or java.lang.UnsatisfiedLinkError's will be generated

VonC
I added JRegistryKey.jar.But Where i have to add the JRegistryKey.dll?
Arivu2020
@Arivu2020: anywhere to one of the path referenced by your environment variable %PATH%, or you can add the path of that dll to your Windows %PATH%. See http://vlaurie.com/computers2/Articles/environment.htm or http://www.computerhope.com/issues/ch000549.htm or http://www.brightrev.com/how-to/windows/35-add-a-utilities-directory-to-your-pc.html?start=1
VonC
just add the dll file in my project is enough to run. Thank you very much VonC
Arivu2020
@Arivu2020: I am glad you made it work in the end.
VonC
+1  A: 

Add the JRegistryKey.jar in the library.
Then copy and paste JRegistryKey.dll in my project.

After that I run the same program ,The registry key is created successfully.

RegistryKey r=new RegistryKey(RootKey.HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run");
        RegistryValue v=new RegistryValue("name or the registrykey",ValueType.REG_SZ,"my jar file path");
        r.setValue(v);
Arivu2020