How to Access Windows Registry From Java

The Windows registry is a posh, hierarchical database that features a multitude of entries detailing details about absolutely anything achieved the usage of Windows. Developers infrequently want to get admission to the Windows registry from inside of a Java applet or utility to be able to learn from the registry, write to present keys, or upload new keys, however this will also be tricky since there is not any outright serve as for this job in Java.

Instead, in most cases 3rd birthday celebration tool is had to get admission to the registry. One such broadly used loose program is known as the JNI Registry library. This Sun authorized library can be utilized to get admission to the Windows registry in addition to for Java categories for tool building.

The procedure will also be reasonably advanced and is best possible tried by means of complicated customers; commercially to be had tool to get admission to the Windows registry from Java is way more practical to make use of (continuously merely requiring a couple of clicks of the mouse) and in most cases rather price efficient. Almost any procedure to get admission to the Windows registry with out the usage of business tool would require codes, hacks, and a minimum of one obtain, if no longer extra. The following is without doubt one of the more uncomplicated strategies, the usage of the least quantity of codes and downloads, to create get admission to to the Windows registry from Java.

Visit a credible website to obtain the registry library.

Right click on the zip report you downloaded and make a selection “Extract To,” then make a selection the specified location for the recordsdata.

Double click on the icon now in your desktop to open the Java IDE (built-in building setting). Once this system is open, make a selection “File,” then click on on “New Java Class” to start out a brand new Java elegance.

You will now import the JNI registry elegance paperwork into your new elegance. To do that, it is important to paste an extended code into the clean elegance report. This code must be enough:

import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;
import com.ice.jni.registry.RegistryValue;

Now you will have to upload new RegistryKey and Registry elegance circumstances. Once this is entire, you’ll then open and edit the registry keys you had been having a look to get admission to for your Java utility or applet. Use this code for the ones functions:

Registry myRegistry = new Registry();
Registry myRegistryKey= Registry.HKEY_CURRENT_USER;
Registry myKey = registry.openSubkey(myRegistryKey,

“SoftwareMicrosoftCurrentVersionExplorerAdvanced”,RegistryKey.ACCESS_ALL);
You can now get to the important thing worth within the Windows registry surroundings to be accessed or changed after which regulate its worth. You will have to use a “take a look at loop” to get admission to the registry whilst in Java as a result of infrequently Java will create a registry exception in an try to save you the failure of the Java program. After working in the course of the take a look at loop whilst in Java, you’ll have entire registry choices. The remaining code you wish to have to for this ultimate step is as follows:

take a look at { RegsitryValue myRegistryValue= myKey.getValue(“good enough”);
myKey.setValue(“Test Value”, myRegistryValue);
myKey.deleteValue(“good enough”); }
catch(RegistryException reEx) {}

Another often used instrument used to get admission to the Windows registry will also be downloaded any place a replica of JWinAPI is to be had. This is a extra advanced instrument than the ones described above, however is understood to be efficient.