Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Windows kernel version in Java?

Tags:

java

I want to get the kernel version in Windows using Java. Is there any class in Java to get the info?

I am able to find the OS name using System.getProperty("os.name");, but I want the kernel version instead.

like image 401
Giri Avatar asked Jun 01 '26 07:06

Giri


1 Answers

With the ver command you can get a more precise kernel version (if needed)

You can execute it using cmd and then parse it


  final String dosCommand = "cmd /c ver";
      final String location = "C:\\WINDOWS\\SYSTEM32";
      try {
         final Process process = Runtime.getRuntime().exec(
            dosCommand + " " + location);
         final InputStream in = process.getInputStream();
         int ch;
         while((ch = in.read()) != -1) {
            System.out.print((char)ch);
         }
      } catch (IOException e) {
         e.printStackTrace();
      }

Result (example)

Microsoft Windows [Version 6.1.7601]
like image 170
Rafael Oltra Avatar answered Jun 04 '26 12:06

Rafael Oltra