USB 일련 번호 가져오기
1253 단어 USB 일련 번호
윈도우만 지원하는 U 디스크 시퀀스 번호를 가진 프로그램
/**
* Description: U
* @author liuwei DateTime 2013-11-4 6:05:56
* @param drive
* @return
*/
public static String getSerialNumber(String drive) {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")
"
+"Set colDrives = objFSO.Drives
"
+"Set objDrive = colDrives.item(\"" + drive + "\")
"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}