Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to write to the registry?

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
i just noticed that a java program i had downloaded had written to the windows registry, at HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs\. how did it do this?

Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
it used nativecode(for example a dll written in C++) and JNI access from java to native code.

Ion Filipski
1c.bmp
 
with a bit of googling, i found an easier solution. you can use the java.util.prefs.Preferences class in jdk1.4 to read from /write to the registry. <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
It is just a happy coincidence what under windows this class write in the registry(but not under other operation systems). It writes in a special place, and you usualy should not know where it writes. But if you want to write especially in registry, update some system or other type of data, you can only use JNI/Win32API

Ion Filipski
1c.bmp
 
java.util.prefs.Preferences is meant to achieve some sort of persistence on any operating system, and if i were concerned with other operating systems i wouldn't want to write a dll in the first place. I'm not concerned with changing registry keys from other applications, so this class works fine... i don't care where it writes (as i don't need to know), just that i have persistence somewhere other than the filesystem (as saving Properties files or serializing objects are too visible to the end user).<br><br>And overall, it's a lot easier and faster to use a built-in java.util.prefs.Preferences object than to figure out the specifics of JNI and how to write and compile my own DLL.<br><br>thanks for the suggestion. <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
I don't mean your specific requirements. Just the question was &quot;ow to write in the registry&quot;, not how to save/update configuration of your program.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top