Java's “os.name” for Windows 10?

后端 未结 5 1338
离开以前
离开以前 2020-12-01 13:49

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

5条回答
  •  日久生厌
    2020-12-01 14:02

    This is definitely a known bug. It occurs because the os.name property gets its value from the GetVersionEx in the source code of the Windows API. GetVersionEx however,

    may be altered or unavailable for releases after Windows 8.1

    As per Microsoft's official website. Instead, we will need to use the IsWindows10OrGreater found in the Version Helper API functions in the versionhelpers.h file. As you probably guessed though, this file is not a Java file, it is written in C. As a result we need to include it in a somewhat roundabout way. It does take quite a bit of work (you need to program in JNI :/) but this tutorial will help you do it. Another solution is shown in this bug log, and does require less effort.

提交回复
热议问题