1

I have some questions about the registry.
We have

Preferences p = Preferences.userRoot();

If we execute

p.nodeExists("/HKEY_CURRENT_USER/Software/Policies/Microsoft")    

it will return true.
After it:

p = p.node("/HKEY_CURRENT_USER/Software/Policies");    
for(String s : p.childrenNames()){
    System.out.println(">" + s);
}

We see that it has one child: "Windows". But

p.nodeExists("/HKEY_CURRENT_USER/Software/Policies/Microsoft/Windows")

returns false. Why?

Thanks.

UPDATE

Ok. I have some mistakes. Let me try again: Why does

p.nodeExists("/HKEY_CURRENT_USER/Software/Policies/Microsoft/Windows") 

return false?

2
  • 1
    Your third code example looks out of sync with the second and fourth ones. Maybe you should review it? Commented Mar 30, 2010 at 20:09
  • OS: Win Xp Pro Sp3; JDK: 1.6.0_10.; User - admin. Commented Mar 31, 2010 at 18:39

2 Answers 2

3

If you execute the code lines shown, in the order shown, when you get to the line

p.nodeExists("/HKEY_CURRENT_USER/Software/Policies/Microsoft/Windows")

p does not anymore point to the user root, but to "/HKEY_CURRENT_USER/Software/Policies".

Btw you have a probable omission in your third code sample:

p = p.node("/HKEY_CURRENT_USER/Software/Policies");    

should be

p = p.node("/HKEY_CURRENT_USER/Software/Policies/Microsoft");    
Sign up to request clarification or add additional context in comments.

6 Comments

As I understand, when i use "/" i'm always linking from root. But, it doesn't matter. Using next code you'll get same result. Preferences p = Preferences.userRoot(); p.nodeExists(.../Microsoft/Windows"); - false p.nodeExists(.../Microsoft")); - true
@Stas You are right (according to the API docs). Puzzling... I actually tried to reproduce it on my machine but I couldn't even get as far as you: could only get a totally empty root node :-(
@Stas I guess it might be somehow related to privileges... What OS and JDK you are using?
I'm using Win Xp Pro Sp3 with jdk1.6.0_10. User - admin.
@Stas That explains why you see those nodes and I don't... Unfortunately I can't log in as admin on my work machine :-(
|
3

I stumbled on this one today. The answer you've accepted is completely wrong.

You seem to be under the impression that Java Preferences is a general tool to manipulate the Windows Registry. It is not. It just so happens that the default implementation of Preferences on the Windows platform happens to store its data in the Windows Registry.

The implementation on Windows stores stuff under the following Registry paths:

For systemRoot: HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs

For userRoot : HKEY_CURRENT_USER\Software\JavaSoft\Prefs

(note: The registry paths changes a bit if you are using a 32bit JRE on a 64-bit OS but that has nothing to do with Java and everything to do with Windows. Sun's code always use the above paths.)

The point to make is that you can maybe use Java Preferences interface to read or change values in the Windows Registry but only below the above registry paths. The reason why I say 'maybe' is that this is just how it happens to be at the moment. Sun/Oracle could at any point in time decide to not to use the Windows Registry or use the Windows Registry but without using sub-nodes, i.e. store everything in one big XML string or something. The point is that Java Preferences is designed to shield you from this.

A lot of Java software that use the Java Preferences provide their own implementation (which is pretty simple to do) to avoid Sun's default implementation that uses the Windows Registry. Not everyone can write to the Windows Registry these days so that was a pretty bad design decision on Sun's part. Fortunately very easy to change.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.