通过调用wmic命令获取硬盘序列号,wmic命令很强大。
Demo:
/**
* 2019年3月13日下午3:48:22
*/
package testReadDiskInfo;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
/**
* @author XWF
*
*/
public class ReadDiskInfo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Process process =Runtime.getRuntime().exec(new String[]{"wmic","diskdrive","get","Index,InterfaceType,SerialNumber"});
process.getOutputStream().close();
Scanner sc=new Scanner(process.getInputStream());
String Index = sc.next();
String InterfaceType = sc.next();
String SerialNumber = sc.next();
List<Map<String,String>> diskList = new ArrayList<>();
while(sc.hasNext()) {
Map<String,String> disk = new HashMap<>();
String index = sc.next();
disk.put(Index, index);
String interfacetype = sc.next();
disk.put(InterfaceType,interfacetype);
String serial = sc.next();
disk.put(SerialNumber, serial);
diskList.add(disk);
}
System.out.println(diskList);
}
}
结果:
![]()
参考:
https://blog.youkuaiyun.com/sinat_35645479/article/details/83024969
本文介绍了一种利用WMIC命令从Windows系统中获取硬盘详细信息的方法,包括硬盘索引、接口类型及序列号,并提供了一个Java实现示例。
2万+

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



