views:

638

answers:

3

Hello

I am writing a Java Applet. When run on Windows, I need to be able to get the clients OS version, e.g. Windows XP SP3 or Windows 2000 SP4.

I can currently use the following:

String os_name    = System.getProperty( "os.name" );
String os_version = System.getProperty( "os.version" );

System.out.println( "Running on " + os_name + "(" + os_version + ")" );

And it will output something like "Running on Windows 2000 (5.0)" which is great but I need to be able to get the service pack version too.

Anybody know how I can get the underlying service pack version of a Windows machine from within a Java applet? (Without throwing an AccessControlException, or ideally without having to self sign the applet).

Many thanks in advance.

A: 

i think you can get it using the 'sun.os.patch.level' property:

String os_sp = System.getProperty( "sun.os.patch.level" );
akf
Thanks, just tried. It works when used in a application but throws an AccessControlException when used from an applet. Thanks though.
QAZ
A: 

Put simply you can't get the value of the sun.os.patch.level property without throwing an AccessControlException.

Applets have security restrictions imposed on.

The only thing you can do is to read on signed applets and policy files for applets

jitter
This is true but perhaps their is another way to determine the service pack level other than trying to read the 'sun.os.patch.level' property?
QAZ
+3  A: 

You can self-sign your java applet:

(stolen from: http://www.captain.at/programming/java/)

Make the certificate:

keytool -export -alias yourkey -file yourcert.crt

Now we have to sign the applet:

Just make a *.bat file including this:

javac yourapplet.java
jar cvf yourapplet.jar yourapplet.class
jarsigner yourapplet.jar yourkey

The batch-file compiles the applet, makes a jar-archive and signs the jar-file.

The HTML-code to display the applet:

<applet code="yourapplet.class" archive="yourapplet.jar" width="600"

height="500">

Now we are done! The applet is signed and if the user accepts the certificate, the applet is allowed to access local files. If the user doesn't agree, you get a java.security.AccessControlException.

So, as long as you don't mind about this little dialog box...

PiPeep
Thanks PiPeep, this would work if I was to use the "sun.os.patch.level" property to get the Service Pack version. Ideally I would prefer not to access this property and thus not have to not sign the applet. If their is no other way this answer is correct.
QAZ