How to Access Windows Registry From Java

0
50
Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  


The Home windows registry is a complex, hierarchical databases that contains a multitude of entries detailing details about just about anything done making use of Home windows. Developers from time to time want to obtain the Home windows registry from within a Java applet or application in order to read through from the registry, produce to present-day keys, or increase new keys, but this can be complicated given that there is no outright perform for this job in Java.

As a substitute, usually third party software package is needed to entry the registry. A person these types of greatly utilized absolutely free program is named the JNI Registry library. This Sun approved library can be utilised to entry the Windows registry as very well as for Java classes for program advancement.

The method can be fairly complicated and is very best tried by innovative users commercially available software to accessibility the Home windows registry from Java is a great deal less complicated to use (typically just necessitating a couple of clicks of the mouse) and commonly rather expense helpful. Almost any procedure to obtain the Home windows registry without having working with business software will involve codes, hacks, and at least just one down load, if not extra. The next is just one of the more straightforward approaches, using the minimum amount of codes and downloads, to build accessibility to the Windows registry from Java.

Stop by a reliable internet site to down load the registry library.

READ  Introduction to Object Serialization in Java part-1

Ideal click on the zip file you downloaded and select “Extract To,” then decide on the desired area for the documents.

Double click on the icon now on your desktop to open up the Java IDE (built-in growth natural environment). At the time the program is open, pick out “File,” then click on “New Java Course” to commence a new Java class.

You will now import the JNI registry course files into your new course. To do this, you will have to have to paste a very long code into the blank course file. This code really should be adequate:

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 must include new RegistryKey and Registry class situations. When that is complete, you can then open up and edit the registry keys you have been seeking to obtain in your Java application or applet. Use this code for people uses:

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

“SoftwareMicrosoftCurrentVersionExplorerAdvanced”,RegistryKey.Accessibility_ALL)
You can now get to the important value in the Home windows registry location to be accessed or modified and then alter its price. You will have to use a “consider loop” to access the registry even though in Java because from time to time Java will build a registry exception in an attempt to protect against the failure of the Java program. After jogging through the try loop though in Java, you will have comprehensive registry possibilities. The final code you need to for this ultimate action is as follows:

check out RegsitryValue myRegistryValue= myKey.getValue(“ok”)
myKey.setValue(“Check Value”, myRegistryValue)
myKey.deleteValue(“alright”)
capture(RegistryException reEx)

READ  All About Class ThreadGroup in Java

An additional often used device made use of to entry the Home windows registry can also be downloaded wherever a copy of JWinAPI is available. This is a more complex device than those explained higher than, but is recognized to be productive.

Resource by Ryan Jennings Smith

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

LEAVE A REPLY

Please enter your comment!
Please enter your name here