JAVA获取CPU、硬盘序列号

/**

* 获取cpu序列号

*  178BFBFF00100F63

*/

public String getCPUSerialNumber() throws IOException {

Process process = Runtime.getRuntime().exec(new String[] { "wmic", "cpu", "get", "ProcessorId" });

process.getOutputStream().close();

Scanner sc = new Scanner(process.getInputStream());

String property = sc.next();

String serial = sc.next();

return serial;

}

/**

* 获取硬盘序列号

*  S4Y3WTDV

*   wmic path win32_physicalmedia get serialnumber

* @throws InterruptedException 

*/

public String getHardDiskSerialNumber() throws IOException, InterruptedException {

//String userName = System.getProperty("user.name").toString();

Process process = Runtime.getRuntime().exec(new String[] { "wmic", "path", "win32_physicalmedia", "get", "serialnumber"});

process.getOutputStream().close();

Scanner sc = new Scanner(process.getInputStream());

String property = sc.next();

String serial = sc.next();

return serial;

}

猜你喜欢

转载自banish.iteye.com/blog/2336178