Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check Windows edition in Java?

I want to check Windows edition (Basic or Home or Professional or Business or other) in Java.

How do I do this?

like image 289
lupchiazoem Avatar asked May 24 '11 11:05

lupchiazoem


3 Answers

You can always use Java to call the Windows command 'systeminfo' then parse out the result, I can't seem to find a way to do this natively in Java.

 import java.io.*;

   public class GetWindowsEditionTest
   {
      public static void main(String[] args)
      {
         Runtime rt; 
         Process pr; 
         BufferedReader in;
         String line = "";
         String sysInfo = "";
         String edition = "";
         String fullOSName = "";
         final String   SEARCH_TERM = "OS Name:";
         final String[] EDITIONS = { "Basic", "Home", 
                                     "Professional", "Enterprise" };

         try
         {
            rt = Runtime.getRuntime();
            pr = rt.exec("SYSTEMINFO");
            in = new BufferedReader(new InputStreamReader(pr.getInputStream()));

            //add all the lines into a variable
            while((line=in.readLine()) != null)
            {
               if(line.contains(SEARCH_TERM)) //found the OS you are using
               {
                //extract the full os name
                  fullOSName = line.substring(line.lastIndexOf(SEARCH_TERM) 
                  + SEARCH_TERM.length(), line.length()-1);
                  break;
               } 
            }

            //extract the edition of windows you are using
            for(String s : EDITIONS)
            {
               if(fullOSName.trim().contains(s))
               {
                  edition = s;
               }
            }

            System.out.println("The edition of Windows you are using is " 
                               + edition); 

         }
            catch(IOException ioe)      
            {   
               System.err.println(ioe.getMessage());
            }
      }
   }
like image 171
Hunter McMillen Avatar answered Sep 18 '22 11:09

Hunter McMillen


You can use the Apache Commons Library

The class SystemUtils provides several methods to determine such information.

like image 33
CubaLibre Avatar answered Sep 19 '22 11:09

CubaLibre


You can get a lot of information about the System you're running on by asking the JVM about it's System Properties:

import java.util.*;
public class SysProperties {
   public static void main(String[] a) {
      Properties sysProps = System.getProperties();
      sysProps.list(System.out);
   }
}

more info here: http://www.herongyang.com/Java/System-JVM-and-OS-System-Properties.html

EDIT: the property os.name seems to be your best bet

like image 24
Bart Vangeneugden Avatar answered Sep 18 '22 11:09

Bart Vangeneugden