programa Java para conseguir Sistema de la placa base del número de serie para Windows o Linux Máquina

Obtener Sistema de la placa base del número de serie de la máquina basada en Linux o Windows : Este programa java obtendrá e imprimir el número de serie de la placa base Linux o sistema operativo Windows máquinas basadas.

package com.includehelp;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class SystemMotherBoardNumber {

public static String getSystemMotherBoard_SerialNumber(){
try{
String OSName= System.getProperty("os.name");
if(OSName.contains("Windows")){
return (getWindowsMotherboard_SerialNumber());
}
else{
return (GetLinuxMotherBoard_serialNumber());
}
}
catch(Exception E){
System.err.println("System MotherBoard Exp : "+E.getMessage());
return null;
}
}

private static String getWindowsMotherboard_SerialNumber() {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs =
"Set objWMIService = GetObject("winmgmts:.rootcimv2")n"
+ "Set colItems = objWMIService.ExecQuery _ n"
+ " ("Select * from Win32_BaseBoard") n"
+ "For Each objItem in colItems n"
+ " Wscript.Echo objItem.SerialNumber n"
+ " exit for ' do the first cpu only! n"
+ "Next n";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception E){
System.err.println("Windows MotherBoard Exp : "+E.getMessage());
}
return result.trim();
}

private static String GetLinuxMotherBoard_serialNumber() {
String command = "dmidecode -s baseboard-serial-number";
String sNum = null;
try {
Process SerNumProcess = Runtime.getRuntime().exec(command);
BufferedReader sNumReader = new BufferedReader(new InputStreamReader(SerNumProcess.getInputStream()));
sNum = sNumReader.readLine().trim();
SerNumProcess.waitFor();
sNumReader.close();
}
catch (Exception ex) {
System.err.println("Linux Motherboard Exp : "+ex.getMessage());
sNum =null;
}
return sNum;
}
public static void main(String[] args) {
String motherBoard_SerialNumber = getSystemMotherBoard_SerialNumber();
System.out.println("MotherBoard Serial Number : "+motherBoard_SerialNumber);
}
}

salida

MotherBoard Serial Number : TFFWB10WB0P4AF


Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *