How to edit a windows registry key value?

There is a specific key in the registry that I would like to edit with java.

The value is a String, in fact, its the 3Dtext screen savers display text.

I do not want to create a new registry key or delete one, I just want to edit one and simply change the string value
of it.

I searched all over google but all I come up with are was to create a new key.

any ideas?

Launch regedit.exe and feed it a prepared *.reg file. (tip: the comments in the file are mandatory!)

Assuming that you’re creating a game, why you need to modify the reg?

well if you would have read my topic post, you would know that haha.

and I don’t understand what you mean by feed the registry a prepared key…?

The reason I am looking to do this through code is because the key will be changing
every so often.

What I am trying to do is have a website where someone, anyone with a link can change the
text of my screen saver with a simple string input. My program, will check for a change in the
string value on the website, and if changed, change the text of my screen saver by editing my
registry.

This has nothing to do with a game and will only affect me.

This doesn’t answer your question, but I’m wondering, have you considered using a Properties file? Is there a specific need to use the registry for this task, or is that you just want to?

That is how the default windows 3d text screen saver gets the text input value. through the registry, therefor I have to use the registry. Unless
I designed my own screen saver which I really dont want to do.

The closest I found to editing, is adding a new key but, that does not help me.

try
	{
		Runtime.getRuntime().exec("REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\your soft\key");
	}
	catch(Exception e)
	{
		System.out.println("Error ocured!");
	}

Im sure there is someway to do it using Runtime. :\

Note that your screen saver will probably need to be re-started in order for the new text to take effect.

You could programatically create a reg file like so:

Header
Blank line
[RegistryPath]
"DataType"="DataValue"
Blank line
Windows Registry Editor Version 5.00

[HKEY_USERS\.DEFAULT\Software\Microsoft\Screensavers\Text3D]
"DisplayString"="Your message here..."
 

More info:
http://support.microsoft.com/kb/310516

This creates a new one, I need to edit an existing one… Unless I can overwrite registry keys? But I don’t think you can.

I don’t have my Windows nearby but as I remember REG files overwrite whatever values are there.

EDIT:
From the MS support site:

[quote]When you run a .reg file, the file contents merge into the local registry. Therefore, you must distribute .reg files with caution.
[/quote]

[/quote]
hmm. i guess i will try the way you posted earlier and see how that works.

I tried the following, but it seemed to do absolutely nothing. didn’t change it at all.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Sofware\Microsoft\Windows\CurrentVersion\Screensavers\ssText3d]
"DisplayString"="This was edited with a reg file"
 

I had an API once that did this. However, it was released very quietly to a small amount of people, on a server far off in the dust.
Just came here to say that a such thing exists, and someone out there has it. The library was called reglib.

It was originally posted here, but links are dead. The author is still active, so you might have some luck.
http://www.rune-server.org/programming/application-development/233446-java-registry-api.html

EDIT:
Heey! Look what I found, using this wonderful new tool that I just recently learned about. It’s almost too good to be true. It’s called Poogle, or something like that.

Java-wise, the second reply to the StackOverflow post with the very complicated class is what you want.
Command line-wise, adding a key that already exists is the same as modifying the key so REG ADD […] is what you want.

I think access to the registry changed slightly with windows 7 (Edit: also Vista), as I have several apps that change registry settings for other related apps, that stopped working with w7. The symptoms were that I could write a new key, but subsequently not modify it. Since these were not my programs (and were not java), the fix was to change the compatibility settings of the EXE to windows XP. This might explain why the REG ADD isn’t working to modify existing entries. Edit: A quick look at regedit shows that keys have security permissions. It may be worth checking that the security permission for the key you want to modify doesn’t appear as read only for your app. I reckon this was done to improve security, so is a good thing.

How did you ‘try’ it?

Did you create a *.reg file and double-click it, or did you call it from Java using Runtime.getRuntime().exec("…") ?

If the latter, you should check out stdout and stderr to look for clues.

I noticed a typo: ‘Sofware’. Might be worth checking it isn’t in your code.

Edit: BTW: I also noticed that if you use REG ADD it needs a /f flag to force an overwrite without a confirm prompt.

Oh wow, @Shane if you did use that, make sure to delete that stray key!

Oh wow I feel stupid now. I read over it for spelling mistakes also and didnt even catch the missing ‘t’.

im pretty sure that was it.

and i tested by make a .reg file. I figured if that worked, it would work using the getRuntime way with command arguments.

Edit:
So that simple type seemed to fix my problem, it updates the key with the correct value, however, the 3dtext screen saver does not seem to want to
use that value as the text. it reverts to the default text of ‘Windows 7’. possibly have to restart my computer? hmm… ill have to look into this further
tomorrow sometime :\

Thanks for the help so far!