wood burning stoves*
The moose likes Java in General and the fly likes Working with registry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Working with registry" Watch "Working with registry" New topic
Author

Working with registry

urfriend pavan
Greenhorn

Joined: Sep 29, 2005
Posts: 1
Hi Friends,
is there a pure java based solution for accessing the windows registry. I read in the Core Java(Sun Publications), that because the registry is a pure windows based concept(component), java don't have any api's for accessing windows registry and you need to go to JNI. Is that so?. Any suggetions are welcome.
Thanks in advance
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

Yes, that is so. The Java API is platform independent, so you will not find platform specific things in there, for example to access the Windows registry.

You could program your own solution using JNI (create some C or C++ code that calls the Win32 API to access the registry), or use one of the libraries available on Internet, for example: http://sourceforge.net/projects/jregistrykey


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
Microsoft has java classes for reading the registry. They're somewhere on my Win98 system in a classes.zip file. That file was created by running a utility program on windows.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
Actually, it's not so. Starting with Java 1.4, the java.util.prefs package does provide access to the Windows registry. On other platforms (Unix et al.), it is mapped to files.


Ping & DNS - my free Android networking tools app
Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
Originally posted by Ulf Dittmer:
Actually, it's not so. Starting with Java 1.4, the java.util.prefs package does provide access to the Windows registry. On other platforms (Unix et al.), it is mapped to files.


Well...yes and no. In the current implementation on windows, the Preferences is mapped to a node in the Registry, but that's not guaranteed. Also, you have NO access to any registry keys other than the ones under :

HK_LOCAL_MACHINE\JavaSoft\Prefs
HK_CURRENT_USER\JavaSoft\Prefs

So it's not really Registry access.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Surely there's a command-line registry-twiddlin' doohickey out there somewhere (there might even be one bundled with Winders.) An alternative to JNI would be to use Runtime.exec() to launch that program.


[Jess in Action][AskingGoodQuestions]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Ernest Friedman-Hill:
Surely there's a command-line registry-twiddlin' doohickey out there somewhere (there might even be one bundled with Winders.)


reg

However, you still can only change what the user has rights to - so there still is a good possibility that it won't work for a "limited account". But you could generate a .bat file and then use runas. This could also be of interest.

PS: If you have a whole slew of changes to make, you could generate a reg file and run
regedit /s filename.reg
See Distributing Registry Changes
or generate an inf file and run
rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 filename.inf
See MS Windows NT Workstation Deployment Guide - Automating Windows NT Setup
[ September 30, 2005: Message edited by: Peer Reynders ]
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
Here's a java program I wrote a couple of years ago that reads registry entries:

 
GeeCON Prague 2014
 
subject: Working with registry