Pages

January 30, 2014

How to get a machine serial number from Java?

import java.util.Scanner;
public class GetMachineSerialNumber
{
    public static void main(String[] args)
    {
        try
        {
            Process process = Runtime.getRuntime().exec(new String[] { "wmic", "bios", "get", "serialnumber" });
            process.getOutputStream().close();
            Scanner sc = new Scanner(process.getInputStream());
            String property = sc.next();
            String serialnum = sc.next();
            System.out.println(property + ": " + serialnum);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}


 OUTPUT: SerialNumber: L908230

1 comment: