Advertisement
Neverlose

Untitled

Jul 4th, 2020
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileWriter;
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5.  
  6. public class MiscUtils {
  7. private MiscUtils() { }
  8.  
  9. public static String getMotherboardSN() {
  10. String result = "";
  11. try {
  12. File file = File.createTempFile("realhowto",".vbs");
  13. file.deleteOnExit();
  14. FileWriter fw = new java.io.FileWriter(file);
  15.  
  16. String vbs =
  17. "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
  18. + "Set colItems = objWMIService.ExecQuery _ \n"
  19. + " (\"Select * from Win32_BaseBoard\") \n"
  20. + "For Each objItem in colItems \n"
  21. + " Wscript.Echo objItem.SerialNumber \n"
  22. + " exit for ' do the first cpu only! \n"
  23. + "Next \n";
  24.  
  25. fw.write(vbs);
  26. fw.close();
  27. Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
  28. BufferedReader input =
  29. new BufferedReader
  30. (new InputStreamReader(p.getInputStream()));
  31. String line;
  32. while ((line = input.readLine()) != null) {
  33. result += line;
  34. }
  35. input.close();
  36. }
  37. catch(Exception e){
  38. e.printStackTrace();
  39. }
  40. return result.trim();
  41. }
  42.  
  43. public static void main(String[] args){
  44. String cpuId = MiscUtils.getMotherboardSN();
  45. javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
  46. null, cpuId, "Motherboard serial number",
  47. javax.swing.JOptionPane.DEFAULT_OPTION);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement