赞
踩
kotlin 序列
The task is to get CPU serial number of Windows Machine.
任务是获取Windows机器的CPU序列号。
- package com.includehelp
-
- import java.io.BufferedReader
- import java.io.File
- import java.io.FileWriter
- import java.io.InputStreamReader
-
-
- /**
- * Method for get Windows Machine CPU Serial Number
- */
- fun getWindowsCPUSerialNumber(): String {
- var result = ""
- try {
- val file = File.createTempFile("realhowto", ".vbs")
- file.deleteOnExit()
- val fw = FileWriter(file)
- val vbs1 = """Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
- Set colItems = objWMIService.ExecQuery _
- ("Select * from Win32_Processor")
- For Each objItem in colItems
- Wscript.Echo objItem.ProcessorId
- exit for ' do the first cpu only!
- Next
- """
- fw.write(vbs1)
- fw.close()
- val p = Runtime.getRuntime().exec("cscript //NoLogo " + file.path)
- val input = BufferedReader(InputStreamReader(p.inputStream))
- var line: String?
- while (input.readLine().also { line = it } != null) {
- result += line
- }
- input.close()
- } catch (E: Exception) {
- System.err.println("Windows CPU Exp : " + E.message)
- }
- return result.trim { it <= ' ' }
- }
-
- //Main Function, Program Entry Point
- fun main(args: Array<String>) {
-
- //Call function get CPU Serial Number
- val cpuSerialNumber = getWindowsCPUSerialNumber()
-
- // Print cpuSerialNumber
- println("Windows Machine CPU Serial Number : $cpuSerialNumber")
- }
Output
输出量
Windows Machine CPU Serial Number : DEEBFBAF000656D4
翻译自: https://www.includehelp.com/kotlin/get-cpu-serial-number-of-windows-machine.aspx
kotlin 序列
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。