File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes General Computing and the fly likes Read windows registry REG_DWORD value  with java.util.prefs.WindowsPreferences Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Read windows registry REG_DWORD value  with java.util.prefs.WindowsPreferences " Watch "Read windows registry REG_DWORD value  with java.util.prefs.WindowsPreferences " New topic
Author

Read windows registry REG_DWORD value with java.util.prefs.WindowsPreferences

sambasivarao laghuvarapu
Greenhorn

Joined: Jun 07, 2007
Posts: 9
The java.util.prefs.WindowsPreferences is the concrete implementation of AbstractPreferences in the Windows platform. This class provides methods like WindowsRegQueryValueEx, etc. Using Reflection, one can use the methods in this class to query string values under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER. For some reason, the java wrapper for WindowsRegQueryValueEx only seems to work for string values. I get a null for values of type REG_DWORD, which I guess makes this approach pretty useless except in times of desperation. Please Tell me how I can retrive REG_DWORD values.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

Don't count on classes not in the public API. They may disappear or change at any time. This includes WindowsPreferences because it's not public.

The Windows native call RegQueryValueEx returns the actual type in its fourth parameter. This call has 6 parameters. In contract, the Java method WindowsRegQueryValueEx only has 2 parameters - the key and the name (as a byte[]). So, Sun discard the actual type at this point. I've checked the source of WindowsPreferences some more, and it totally ignores the possible type - it just treats the byte[] returned by the method as a String. I recon WindowsRegQueryValueEx returns null if the actual registry value type is not a string. This makes me believe that WindowsPreferences convert any input to and from REG_SZ (stirng).

If I were you, I'd go and find a third party registry library that uses JNI. Check out http://www.google.com/search?client=opera&rls=en&q=java+windows+registry&sourceid=opera&ie=utf-8&oe=utf-8 and JNIRegistry from http://www.gjt.org/download/. The latter has a class RegistryValue with subclasses RegBinaryValue, RegDWordValue, RegMultiStringValue and RegStringValue. With those, the only types you're missing are REG_DWORD_BIG_ENDIAN, REG_LINK, REG_NONE, REG_QWORD and REG_QWORD_LITTLE_ENDIAN.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Not a beginner's question. Moving.
manjula sharma
Greenhorn

Joined: Dec 14, 2009
Posts: 2
Rob Prime wrote:Don't count on classes not in the public API. They may disappear or change at any time. This includes WindowsPreferences because it's not public.

The Windows native call RegQueryValueEx returns the actual type in its fourth parameter. This call has 6 parameters. In contract, the Java method WindowsRegQueryValueEx only has 2 parameters - the key and the name (as a byte[]). So, Sun discard the actual type at this point. I've checked the source of WindowsPreferences some more, and it totally ignores the possible type - it just treats the byte[] returned by the method as a String. I recon WindowsRegQueryValueEx returns null if the actual registry value type is not a string. This makes me believe that WindowsPreferences convert any input to and from REG_SZ (stirng).

If I were you, I'd go and find a third party registry library that uses JNI. Check out http://www.google.com/search?client=opera&rls=en&q=java+windows+registry&sourceid=opera&ie=utf-8&oe=utf-8 and JNIRegistry from http://www.gjt.org/download/. The latter has a class RegistryValue with subclasses RegBinaryValue, RegDWordValue, RegMultiStringValue and RegStringValue. With those, the only types you're missing are REG_DWORD_BIG_ENDIAN, REG_LINK, REG_NONE, REG_QWORD and REG_QWORD_LITTLE_ENDIAN.



which one download from page: http://www.gjt.org/download/ to get thired party registry library that uses JNI???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
manjula sharma wrote:which one download from page: http://www.gjt.org/download/ to get thired party registry library that uses JNI?

Are you asking how to find the string "JNIRegistry" -which Rob mentioned was the project's name- on that page?
manjula sharma
Greenhorn

Joined: Dec 14, 2009
Posts: 2
Ulf Dittmer wrote:
manjula sharma wrote:which one download from page: http://www.gjt.org/download/ to get thired party registry library that uses JNI?

Are you asking how to find the string "JNIRegistry" -which Rob mentioned was the project's name- on that page?


I am using java.util.pref.WindowsPreferences to read windows registry values.
but it returns NULL for all key value data which is not of type String.
(Same problem as posted at the top of this page)
Is there anyother JNI to solve the issue, where to download it??
Tobias Hoppenthaler
Greenhorn

Joined: Feb 20, 2011
Posts: 5
I am experiencing the same problems - guess you have found a solution by now, if not, here's a thread that might help.
http://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read windows registry REG_DWORD value with java.util.prefs.WindowsPreferences