How to create a registry key through a java program?

I want to create a registry key through a java program to add a jar file to the beginning.

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 this?
Thanks

+4
source share
3 answers

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

After that I run the same program, the registry key has been successfully created.

 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); 
+4
source

From Javadoc :

It is thrown if the Java virtual machine cannot find a suitable language definition based on the native language.

Would you not be able to win 64 OS by accident?

If not, the manual for jreg mentions :

jRegistryKey is a JNI library. The following files are required to use jRegistryKey :

  • jRegistryKey.jar
  • jRegistryKey.dll

jRegistryKey.jar is a Java โ„ข Archive (JAR) file containing packed Java โ„ข class files, while jRegistryKey.dll is a dyanmically linked Windows library (DLL) that contains its own (C / C ++) code needed to access the registry.

jRegistryKey.jar must be included in CLASSPATH , available for the Java โ„ข Virtual Machine (JVM);

jRegistryKey.dll must be located in the directory included in the Windowsยฎ PATH environment variable, or java.lang.UnsatisfiedLinkError will be generated

+7
source

Adding jregistrykey.dll to my project did not work for me. I included this block in my class and it worked.

 static { System.load("path\\to\\jregistrykey.dll"); } 
+1
source

Source: https://habr.com/ru/post/1306763/


All Articles