如何使用cmd获取硬盘序列号

时间:2014-11-04 08:20:33

标签: cmd window command admin

我使用命令查找硬盘序列号" wmic diskdrive get serialnumber"但我插入一个外部设备,如硬盘或平移驱动器,此命令提供外部硬盘或平移驱动器的信息。那么怎样才能找到安装系统窗口的内部硬盘信息。

1 个答案:

答案 0 :(得分:0)

public String HDD_SerialNo(){
    StringBuffer HDD_Serial=new StringBuffer();
    String HDD_Number;
    Runtime rt = Runtime.getRuntime();
    try {
        Process process=rt.exec(new String[]{"CMD", "/C", "WMIC diskdrive get serialnumber"});
        String s = null;
        //Reading sucessful output of the command
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        while ((s = reader.readLine()) != null) {
            HDD_Serial.append(s);
        }
        // Reading error if any
        reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        while ((s = reader.readLine()) != null) {
         System.out.print(s);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    HDD_Number=HDD_Serial.toString();
    return HDD_Number;
}