java 如何通过java程序创建注册表项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2627446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to create registry key through java program?
提问by Arivu2020
I want to create registry key through java program to add the jar file in the start up.
我想通过java程序创建注册表项以在启动时添加jar文件。
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
我怎样才能做到这一点?
谢谢
回答by VonC
From the Javadoc:
从Javadoc:
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
如果 Java 虚拟机找不到声明为 native 的方法的适当本地语言定义,则抛出。
You wouldn't be on a win 64OS by any chance?
万一您不会使用 win 64操作系统?
If not, the manual for jreg mentions:
jRegistryKeyis aJNIlibrary. To usejRegistryKey, the following files are required:
jRegistryKey.jarjRegistryKey.dlljRegistryKey.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.jarmust be included in theCLASSPATHavailable to the Java? Virtual Machine (JVM);
jRegistryKey.dllmust be located in a directory included in the Windows? PATH environment variable orjava.lang.UnsatisfiedLinkError's will be generated
jRegistryKey是JNI图书馆。要使用jRegistryKey,需要以下文件:
jRegistryKey.jarjRegistryKey.dlljRegistryKey.jar 是Java 吗?包含打包的 Java 的存档 (JAR) 文件?class 文件,而 jRegistryKey.dll 是 Windows?动态链接库 (DLL),包含访问注册表所需的本机 (C/C++) 代码。
jRegistryKey.jar必须包含在CLASSPATH可用的 Java 中吗?虚拟机(JVM);
jRegistryKey.dll必须位于包含在 Windows 中的目录中吗?java.lang.UnsatisfiedLinkError将生成PATH 环境变量或's
回答by Arivu2020
Add the JRegistryKey.jarin the library.
Then copy and paste JRegistryKey.dllin my project.
JRegistryKey.jar在库中添加。
然后复制并粘贴JRegistryKey.dll到我的项目中。
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);
回答by Abdul Rehman
Adding jregistrykey.dll in my project didn't work for me. I included this block in my class and it worked.
在我的项目中添加 jregistrykey.dll 对我不起作用。我在我的班级中加入了这个块并且它起作用了。
static {
System.load("path\to\jregistrykey.dll");
}

