How to write Windows Registry using Java code/program?
I searched so many site to write Windows Registry using java code/program but there is not any good information available on internet. I came with new API javaQueryAPI that will help you to write windows Registry using java code.
Important notice for existing user ( javaQueryAPI 7.0 or less ) :
Thanks for using javaQueryAPI bundle. I've made major changes in javaQueryAPI 8.0 so don't import this bundle if you don't want to change the code of your code. Many classes exist in javaQueryAPI 7.0 will no longer available in javaQueryAPI 8.0. I'm going to give you code snippet for existing and new javaQueryAPI.
The above code works for javaQueryAPI 7.0 or less. For new javaQueryAPI 8.0 check out the below code snippet.
You must follow rules to create new - for existing Registry key:
Important notice for existing user ( javaQueryAPI 7.0 or less ) :
Thanks for using javaQueryAPI bundle. I've made major changes in javaQueryAPI 8.0 so don't import this bundle if you don't want to change the code of your code. Many classes exist in javaQueryAPI 7.0 will no longer available in javaQueryAPI 8.0. I'm going to give you code snippet for existing and new javaQueryAPI.
/* * javaQueryAPI 7.0 or less * method : (RKey,path,keyType,Name,Value); * RKey : Root key (folder) to create the registry. (i.e : HKEY_CURRENT_USER ) * path : Folder path of your software or existing folder that must starts with (\\). (i.e : \\software\\microsoft) * keyType : Its a keyType that you want to create DWORD,String,Binary. * Name : Name of key. * Value: Value of key. */ import javaQuery.core.Rkey; import javaQuery.core.keyType; public class jqRegDemo { public static void main(String[] args) { jqReg _jr = new jqReg(); String message = _jr.jqReg(RKey.HKEY_CURRENT_USER, "\\jqReg",keyType.Dword, "test","00000320"); System.out.println("Response: "+message); } }
The above code works for javaQueryAPI 7.0 or less. For new javaQueryAPI 8.0 check out the below code snippet.
/* * javaQueryAPI 8.0 or above * method : (RegistryKey,path,keyType,Name,Value); * RegistryKey : Root key (folder) to create the registry. (i.e : HKEY_CURRENT_USER ) * path : Folder path of your software or existing folder that must starts with (\\). (i.e : \\software\\microsoft) * keyType : Its a keyType that you want to create DWORD,String,Binary. * Name : Name of key. * Value: Value of key. * javaQueryBundle.createRegistry() is new class created for better use. That allows you to overcome from creating object of class. * I prefer you to use IDE so it'll give you better idea of class covered in javaQueryBundle. */ import javaQuery.core.Registry; import javaQuery.importClass.javaQueryBundle; public class Demo { public static void main(String[] args) { String response = javaQueryBundle.createRegistry().createKey(Registry.HKEY_CURRENT_USER, "\\jqreg", Registry.key_String_Value, "Software", "javaQueryAPI"); System.out.println(response); } }
You must follow rules to create new - for existing Registry key:
- When you want to change (Default) value give key name as (Default). It'll change default value.
- String value = "\\\"javaw.exe\\\" \\\"-jar\\\" \\\"c:\\\\jqEditor\\\\jqEditor.jar\\\" \\\"%1\\\"" this will set value as "javaw.exe" "-jar" "c:\jqEditor\jqEditor.jar" "%1"
- If Registry value contains double quote ( " ) then you have to use ( \ ). for example check rule 2.
- If Registry value contains forward slash ( \ ) then also you have to use ( \ ). for example check rule 2.
- You must have admin rights of system to create Registry.
Check out the http://www.javaquery.com/p/downloads.html for download.
Can't help getting the same error over and over again:
ReplyDeleteResponse: java.io.FileNotFoundException: C:\jqReg.bat (Access is denied)
Whole code would look like:
package Main;
import javaQuery.core.RKey;
import javaQuery.core.jqReg;
import javaQuery.core.keyType;
public class Main
{
public static void main(String[] args)
{
jqReg _jr = new jqReg();
String message = _jr.jqReg(RKey.HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Main\\",keyType.Dword, "test","00000320");
System.out.println("Response: "+message);
}
}
Because you don't have admin access rights...thats why its giving error...
ReplyDeletepublic static void main(String[] args) {
ReplyDeletejqReg _jr = new jqReg();
String message = _jr.jqReg(RKey.HKEY_CURRENT_USER, "\\jqReg",keyType.Dword, "test","00000320");
System.out.println("Response: "+message);
}
i build succesful Response: Created Thank you for using jqReg Visit http://www.javaquery.com
but when i open regedit i dont see any jqReg Key in HKEY_CURRENT_USER
please help me
Its working fine on my machine. I think you don't have rights(user rights) to write registry key. You must need Admin access of machine.
ReplyDelete