Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java's "os.name" for Windows 10?

In Java, we can see the property value of os.name to know the name of the underlying operating system: System.getProperty("os.name").

For each edition of Windows, it used to return always the exact name of the OS: Windows XP for XP, Windows Vista for Vista, Windows 7 for Seven, Windows 8.1 for 8.1, and so on...

The problem is: I just updated my Windows 8.1 to Windows 10 using the released Microsoft updater, and it seems like this property still remains Windows 8.1:

public class OSTest {   public static void main(String[] args) {     System.out.println(System.getProperty("os.name"));   } } 

How can I create a workaround for this? And, does anyone know if this problem persists if installing a fresh Windows 10 copy - that is, this bug is caused by the Microsoft auto-updater -?

like image 917
JoaaoVerona Avatar asked Aug 09 '15 21:08

JoaaoVerona


People also ask

What is os name for Windows?

Microsoft Windows is a major computer operating system developed by Microsoft.

What is the OS version of Windows 10?

Version 20H2 (October 2020 Update)

How to find the os in Java?

Use the System. getProperty() method in Java to get the Operating System name.

Which of the following can be used to return the name of the operating system?

The System. getProperty("os.name") returns the name of the os as a string.


1 Answers

This is a known problem JDK-8066504 that has been fixed in upcoming Java 8 update 60.

The reason is GetVersionEx function has changed its behavior since Windows 8.1.

There are multiple possible workarounds, see MSDN article.

The trivial one is to exec cmd.exe /c ver.

The other is to look at the version information of one of the system files, e.g. kernel32.dll.

like image 53
apangin Avatar answered Oct 19 '22 10:10

apangin