Page 1 of 1

How to access Windows Registry from Java

Posted: Fri Nov 27, 2009 3:20 am
by Saman
Here is a easy way to access Windows registry from Java the easy way via API . Otherwise you should be writing JNI code to access registry which is a demanding job for a newbie.
  1. JNIRegistry
  2. JWinAPI
    JWinAPI is even more versatile and Powerful because it is not only allowing to access Registry from java but also allows you to use almost all Windows API in Java Directly just by including this API in your Project.
Steps to use JWinAPI
There are certain important functionalities in Win32 API like getting Window handles, Spawning new process, killing process, Send Keystrokes, Tweaking Registry, Logging lots and lots more.

Follow the listed steps:
  1. Visit this page
  2. Download copy of JWinAPI
  3. Install the using setup
  4. Include JWinAPI.jar in your Project Library.
  5. Done!
Go to the directory where you have installed JWinAPI. Type:

Code: Select all

java -jar JWinAPI.jar
Example 1: Displaying a message box

Code: Select all

WinAPI wapi = new JWinAPI();
	wapi.doMessageBox("JWinAPI DLL has been loaded successfully!",
			"JWinAPI", MBConstants.MB_OK + MBConstants.MB_ICONASTERISK );
Example 2: Accessing the registry

Code: Select all

// write an int value
	wapi.doWriteToRegistry(REGConstants.HKEY_CURRENT_USER,
		"Software\\ROBOT.LK\\regsample",
		"javaINTValue",	REGConstants.REG_DWORD, new Integer(876543) ) ;