开发者

how to create registry key through java program?

开发者 https://www.devze.com 2022-12-26 09:28 出处:网络
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\");

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开发者_Python百科.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


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


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


Adding jregistrykey.dll in my project didn't work for me. I included this block in my class and it worked.

static {
    System.load("path\\to\\jregistrykey.dll");
}
0

精彩评论

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