Skip to main content

How to get Mother Board Serail Number

1 reply [Last post]
umeshrama
Offline
Joined: 2009-01-02
Points: 0

Dear Sir/Madam

Please Help me
How to read System mother board Serial number or HDD serial number
in simple java code.
or is there any API to get the Serial Number
please help..........

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zumbo260
Offline
Joined: 2010-04-01
Points: 0

I use Shell.jar to execute a command and get the result.
It is hardware and operating system dependent, but it's work onUbuntu 9.04 and can be adapted for Windows.
/**
* Récupère le UUID d'un disque en passant une commande shell :
* "ls -l /dev/disk/by-uuid | grep " + dev
*
* lrwxrwxrwx 1 root root 9 2010-03-04 19:43 D033-F71A -> ../../sde
*
* @param devDevice = "/dev/sdb5" p.e.
* @return "fab36b9f-8dec-4303-817b-873a53768351" p.e.
*/
private static String getLinuxLabelForDevice (String devDevice) {
String retour = null;
String dev = devDevice.substring(devDevice.lastIndexOf("/") + 1);
String commande = "ls -l /dev/disk/by-label | grep " + dev;
try {
Shell sh = new Shell();
ProcessConsumer pc = sh.command(commande);
String ligne = pc.consumeAsString();
// Si la ligne n'est pas vide, on l'a dissocie en mots
// et l'on garde celui qui précède "->"
if (ligne != null && ligne.length() > 0) {
String [] mots = ligne.split(" ");
for (int i = 0 ; i < mots.length ; i++) {
if (mots[i].compareTo("->") == 0) {
retour = mots[i - 1];
break;
}
}
}
return retour;
} catch (IOException ex) {
leJournal.log(Level.SEVERE, null, ex);
return retour;
}
}