当前位置:   article > 正文

kotlin 序列_Kotlin程序获取Windows机器的CPU序列号

kotlin 设备序列号

kotlin 序列

The task is to get CPU serial number of Windows Machine.

任务是获取Windows机器的CPU序列号。

  1. package com.includehelp
  2. import java.io.BufferedReader
  3. import java.io.File
  4. import java.io.FileWriter
  5. import java.io.InputStreamReader
  6. /**
  7. * Method for get Windows Machine CPU Serial Number
  8. */
  9. fun getWindowsCPUSerialNumber(): String {
  10. var result = ""
  11. try {
  12. val file = File.createTempFile("realhowto", ".vbs")
  13. file.deleteOnExit()
  14. val fw = FileWriter(file)
  15. val vbs1 = """Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  16. Set colItems = objWMIService.ExecQuery _
  17. ("Select * from Win32_Processor")
  18. For Each objItem in colItems
  19. Wscript.Echo objItem.ProcessorId
  20. exit for ' do the first cpu only!
  21. Next
  22. """
  23. fw.write(vbs1)
  24. fw.close()
  25. val p = Runtime.getRuntime().exec("cscript //NoLogo " + file.path)
  26. val input = BufferedReader(InputStreamReader(p.inputStream))
  27. var line: String?
  28. while (input.readLine().also { line = it } != null) {
  29. result += line
  30. }
  31. input.close()
  32. } catch (E: Exception) {
  33. System.err.println("Windows CPU Exp : " + E.message)
  34. }
  35. return result.trim { it <= ' ' }
  36. }
  37. //Main Function, Program Entry Point
  38. fun main(args: Array<String>) {
  39. //Call function get CPU Serial Number
  40. val cpuSerialNumber = getWindowsCPUSerialNumber()
  41. // Print cpuSerialNumber
  42. println("Windows Machine CPU Serial Number : $cpuSerialNumber")
  43. }

Output

输出量

Windows Machine CPU Serial Number : DEEBFBAF000656D4


翻译自: https://www.includehelp.com/kotlin/get-cpu-serial-number-of-windows-machine.aspx

kotlin 序列

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/259916?site
推荐阅读
相关标签
  

闽ICP备14008679号