How can I write System preferences with Java? Can I invoke UAC?

Posted by Jonas on Stack Overflow See other posts from Stack Overflow or by Jonas
Published on 2010-05-29T17:16:16Z Indexed on 2010/05/29 17:22 UTC
Read the original article Hit count: 335

How can I write system preferences with Java, using Preferences.systemRoot()?

I tried with:

Preferences preferences = Preferences.systemRoot();
preferences.put("/myapplication/databasepath", pathToDatabase);

But I got this error message:

2010-maj-29 19:02:50 java.util.prefs.WindowsPreferences openKey
VARNING: Could not open windows registry node Software\JavaSoft\Prefs at root 0x80000002. Windows RegOpenKey(...) returned error code 5.
Exception in thread "AWT-EventQueue-0" java.lang.SecurityException: Could not open windows registry node Software\JavaSoft\Prefs at root 0x80000002: Access denied
    at java.util.prefs.WindowsPreferences.openKey(Unknown Source)
    at java.util.prefs.WindowsPreferences.openKey(Unknown Source)
    at java.util.prefs.WindowsPreferences.openKey(Unknown Source)
    at java.util.prefs.WindowsPreferences.putSpi(Unknown Source)
    at java.util.prefs.AbstractPreferences.put(Unknown Source)
    at biz.accountia.pos.install.Setup$2.actionPerformed(Setup.java:43)

I would like to do this, because I want to install an embedded JavaDB database, and let multiple users on the computer to use the same database with the application.

How to solve this? Can I invoke UAC and do this as Administrator from Java? And if I log in as Administrator when writing, can I read the values with my Java application if I'm logged in as a User?

© Stack Overflow or respective owner

Related posts about java

Related posts about Windows