|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
对于jsa来说真费劲,大概思路是执行shell命令,将shell结果写入txt。读txt,取序列号,删txt
- function getSerialNumber(){
- //建立一个txt用来存放shell命令的结果
- let outPutTxt=ThisWorkbook.Path + '\\output.txt'
- let outPutShell ='"' + outPutTxt + '\\output.txt' + '"'
- //执行shell命令,获取磁盘序列号,并将结果存入oupPutTxt
- Shell(`powershell "Get-WmiObject -Class Win32_DiskDrive | Select-Object SerialNumber | Out-String -Stream | Set-Content '${outPutShell}'"`,jsHide)
- //读取txt
- let resArr=read(outPutTxt); //["","SerialNumber ","------------ ","AA000000000000001657","",""]
- //取序列号 注意,一台电脑可能有多个硬盘
- let serialNumber=resArr[3];
- Console.log(serialNumber) ////AA000000000000001657
- Kill(outPutTxt) //删除临时文件
- }
- function read(txt) {
- var no = FreeFile()
- var fn = Open(txt, no, 4, jsReadWrite, jsLockWrite, 10000)
- var data =[];
- while (!EOF(no)) {
- data.push(LineInput(no))
- }
- Close(no)
- return data;
- }
复制代码 |
|