/**
* 获取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;
}
本文介绍了一种使用Java程序来获取计算机的CPU序列号和硬盘序列号的方法。通过调用`wmic`命令并解析其输出,实现了序列号的读取。此方法适用于Windows平台。
2262

被折叠的 条评论
为什么被折叠?



