Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working with registry

 
urfriend pavan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Norm Radder
Bartender
Posts: 1355
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1355
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a java program I wrote a couple of years ago that reads registry entries:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic