Created
December 11, 2018 04:52
-
-
Save S4WA/9534ce720d05f9a63056b9b32a7d82d2 to your computer and use it in GitHub Desktop.
hardware uuid gen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.InputStreamReader; | |
import java.util.UUID; | |
public class HWUUIDGenerator { | |
private String uuid; | |
public final String onGenerateUUID() { | |
String result = ""; | |
try { | |
File file = File.createTempFile("realhowto", ".vbs"); | |
file.deleteOnExit(); | |
FileWriter fw = new FileWriter(file); | |
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\nSet colDrives = objFSO.Drives\nSet objDrive = colDrives.item(\"C:\")\nWscript.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 += line; | |
input.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
UUID u2 = UUID.nameUUIDFromBytes(result.getBytes()); | |
this.uuid = u2.toString(); | |
System.out.println("Successfully generated UUID:" + this.uuid); | |
return this.uuid; | |
} | |
public String getUUID() { | |
return this.uuid; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment