硬盘序列号是硬盘格式化时系统随机分配给硬盘的一组十六进制字符串,除分对硬盘重新进行格式化,硬盘序列号是不会改变的。所以,很多软件都会以硬盘序列号判断用户是否合法用户。以下是JAVA获取硬盘序列号的方法。
public static String getHdSerialInfo() {
String line = "";
String HdSerial = "";//记录硬盘序列号
try {
Process proces = Runtime.getRuntime().exec("cmd /c dir c:");//获取命令行参数
BufferedReader buffreader = new BufferedReader(
new InputStreamReader(proces.getInputStream()));
while ((line = buffreader.readLine()) != null) {
if (line.indexOf("卷的序列号是 ") != -1) { //读取参数并获取硬盘序列号
HdSerial = line.substring(line.indexOf("卷的序列号是 ")
+ "卷的序列号是 ".length(), line.length());
break;
// System.out.println(HdSerial);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return HdSerial;返回硬盘序列号
}