最近抓取主板UUID,到处请教后总结
参考:
一、获取UUID
1.powershell用法
powershell (get-wmiobject Win32_ComputerSystemProduct).UUID
2.wmic用法
wmic csproduct get uuid
二、去掉“-”
powershell (get-wmiobject Win32_ComputerSystemProduct).UUID.Replace('-','')
三、去掉换行符
生成的数据有第二行,光标并不在第一行结尾
方法一、
@echo off
for /f %%a in ('wmic path Win32_ComputerSystemProduct get uuid /value^|find "="') do set %%a
set /p=%uuid:-=%<nul>"uuid.txt"
pause
方法二、
@echo off
for /f %%a in ('powershell "(gwmi Win32_ComputerSystemProduct).UUID.Replace('-','')"') do set/p=%%a<nul>"uuid.txt"
pause
方法三、
@echo off
powershell ^
$fso=New-Object -ComObject Scripting.FileSystemObject;^
$uuid=(gwmi Win32_ComputerSystemProduct).UUID.Replace('-','');^
$fso.CreateTextFile('uuid.txt', 2).Write($uuid);
pause
四、获取UUID最后12位
for /f %%a in ('powershell "(gwmi Win32_ComputerSystemProduct).UUID.Substring(((gwmi Win32_ComputerSystemProduct).UUID).Length-12)"') do set/p=%%a<nul>"uuidmac.txt"