I have a Java program which needs to write to the system wide preferences via Preferences.systemRoot(). It works correctly when run by double clicking the Jar file but it fails with a BackingStoreException when run using the launcher created by Advanced Installer, I believe because it is being denied permission to write to the Windows Registry. If I right click on the launcher icon and select "Run as administrator", it actually works. It also works if I run the program from the command line or by double clicking the Jar. The problem occurs on Windows Vista when running Java 1.6.0_01-b06 (i.e., the latest release).
I created a bare bones test case to demonstrate this. I created it from scratch and using a different company name and settings from my main project, in order to avoid any Windows registry settings that might be causing this. Here is a program which demonstrates the problem:
Code: Select all
import java.io.*;
import java.util.prefs.*;
import javax.swing.*;
public class SetDummyPref {
public static void main (String[] arg) {
String message;
// attempt to set a preference
try {
String path = "/com.pensamos/dummyPref";
final Preferences prefs = Preferences.systemRoot().node(path);
prefs.putLong("dummyKey", System.currentTimeMillis());
prefs.flush();
message = "Success!";
}
// extract stack trace from exception
catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
message = sw.toString();
}
// print the result;
message = System.getProperty("java.runtime.version") + "\n\n" + message;
JTextArea ta = new JTextArea(message);
JScrollPane sp = new JScrollPane(ta);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(sp);
f.pack();
f.setVisible(true);
f.toFront();
}
}
Code: Select all
Manifest-Version: Version 1.0
Main-Class: SetDummyPref
Thanks,
- Tim Macinta
FOLLOW US
Get the latest news in Application Packaging