Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Better way to access Windows registry?

807580Jun 11 2010
After some searching, I have come across several ways to read arbitrary registry values:
1. jRegistryKey - this doesn't work in 64-bit Java; I suspect any JNI would need two separate dlls to be able to run in both 32-bit and 64-bit Java. I also have a vague memory that its method to check for the existence of a registry key doesn't work properly, and threw an exception instead of just returning false, but that may have been fixed by now.
2. JNIRegistry - I only saw one dll, so I figure this would probably hit the same problem with 32-bit vs. 64-bit.
3. NativeCall - does more than just registry handling, but again, one dll probably limits it to 32-bit Java
4. JWinAPI - I can't find adequate documentation for it; it looks like it uses an exe rather than a dll, but here again I doubt it would work for both 32-bit and 64-bit Java.
5. Preferences hacking - I don't consider this reliable, because it forces access to private methods of a private class, and the names of those private methods could change in a newer version of Java (also, it violates the separation of interface and implementation)
6. "reg.exe query" - works in both 32-bit and 64-bit Java (I know from personal experience), but breaks keys, value names, and data that can't be represented with an 8-bit character set. Also, this requires parsing.
7. "reg.exe export" - deals with 16-bit characters better, but outputs to a file which has to then be read and parsed, so it's a bit slower.
Using "reg.exe" has the advantage that it can be separately elevated in Vista or Windows 7 for creating or deleting keys without elevating the whole Java program.

However, I'm wondering if there's a better way to do this, such as a JNI-based library that runs in both 32-bit and 64-bit Java (with alternate dlls), or a library that launches "reg.exe" for different things, and could take care of the parsing for me (and maybe optionally elevate (with UAC prompt) when creating or deleting keys).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 9 2010
Added on Jun 11 2010
0 comments
167 views