Skip to content

Instantly share code, notes, and snippets.

@LeoFalco
Created October 16, 2018 21:52
Show Gist options
  • Save LeoFalco/2fa7188f87cd5351a0c9e071d5a1d4ee to your computer and use it in GitHub Desktop.
Save LeoFalco/2fa7188f87cd5351a0c9e071d5a1d4ee to your computer and use it in GitHub Desktop.
consultar serial HD
public String consultarSerialHD(String drive) {
StringBuilder result = new StringBuilder();
try {
File file = File.createTempFile("tmp", ".vbs");
file.deleteOnExit();
FileWriter fw = new FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" + "Set colDrives = objFSO.Drives\n"
+ "Set objDrive = colDrives.item(\"" + drive + "\")\n" + "Wscript.Echo objDrive.SerialNumber";
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.append(line);
}
input.close();
} catch (Exception ignored) {
}
if (result.length() < 7) {
result = new StringBuilder("0135768901");
} else if (result.length() == 8) {
result.insert(0, "00");
} else if (result.length() == 9) {
result.insert(0, "0");
} else if (result.length() > 10) {
result = new StringBuilder(result.substring(0, 10));
}
return result.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment