How to obtain the windows OEM license directly from the PC BIOS using JAVA?

-3

I am developing a computer inventory program for the company where I work which is able to identify hardware and other features of the machine, however in the inventory it should go:

  • windows distribution
  • product id
  • installed license and
  • BIOS license

This last one has been impossible to obtain since I do not know how to find the OEM license of the BIOS of the PC, I have developed the program in JAVA.

I tried to use this code but it does not work, it stays in a kind of LOOP but I do not know why,

String comando = "powershell.exe (Get-WmiObject -query 'SELECT OEMStringArray FROM Win32_ComputerSystem').OA3xOriginalProductKey ";
Process p = Runtime.getRuntime().exec(comando);
String line;
System.out.println("Standard Output:");
BufferedReader stdout = new BufferedReader(new InputStreamReader(
        p.getInputStream()));
while ((line = stdout.readLine()) != null) {
    System.out.println("hola");
    System.out.println(line);
}
stdout.close();
System.out.println("Standard Error:");
BufferedReader stderr = new BufferedReader(new InputStreamReader(
        p.getErrorStream()));
while ((line = stderr.readLine()) != null) {
    System.out.println(line);
}
stderr.close();
System.out.println("Done");
    
asked by Nicolas García 26.07.2018 в 22:40
source

1 answer

0

The command works perfectly.

In Java you could use something like this:

import static java.lang.System.out;
import static java.lang.system.err;
//...
//...
    try{
                String result = null;
    //String comando = "(Get-WmiObject -query 'SELECT OEMStringArray FROM Win32_ComputerSystem').OA3xOriginalProductKey ";

//Obtener información del BIOS
//String comando = "WMIC /Output:STDOUT BIOS get /all /format:LIST";

    String comando = "wmic baseboard get serialnumber";

                Process p = Runtime.getRuntime().exec(comando);
                BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String line;
                while ((line = input.readLine()) != null){
                    result += line;
                }
                if(result.equalsIgnoreCase(" ")) {
                    out.println("El resultado esta vacio");
                } else{
                    javax.swing.JOptionPane.showMessageDialog(null,result);
                }
                input.close();
            } catch (IOException ex){
                err.println("Ha ocurrido una excepcion");
                err.println("Estas en una plataforma ajena a Windows?");
                //ex.printStackTrace();
            }

I leave this post about the use of WMIC link

There are several combinations to use WMIC and get what you require

    
answered by 27.07.2018 / 18:24
source