2013-06-24 51 views
3

我想使用Java在Windows中獲取內核版本。 Java中有沒有任何類來獲取信息?在Java中獲取Windows內核版本?

我能找到使用System.getProperty("os.name");的操作系統名稱,但我想要內核版本。

+1

我能問你,爲什麼需要? – ajduke

回答

1

你嘗試:

System.getProperty("os.version"); 

如果你想檢查相同的Linux或Android,你可以通過這個聲明這樣做:

Runtime.getRuntime().exec("uname -r"); 
+0

與os.version它給6.1輸出。但我不確定Windows版本是否與內核版本相同。 – Giri

+0

但我需要它在Windows中...我發現Linux或Android的幾個鏈接,但爲Windows。 – Giri

3

隨着版本命令你可以得到一個更精確的內核版本(如果需要)

你可以使用cmd執行它然後解析它


    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(); 
     } 

結果(例如)

 
Microsoft Windows [Version 6.1.7601]