批处理脚本正在导出奇怪的字符
Batch Script is exporting weird characters
我的脚本有问题。我会post它。
它运行良好,直到到达这条线:
wmic diskdrive list full | findstr /B "Size=" >> %cd%ProductCodes\%Serial%\PCINFO.txt
这是它发送到文件的内容...
枫驱ㄽ㐲ㄱ㈱㤴㈹ര枫驱㈽㘵㔰㤲㘶〴ര
如有任何帮助,我们将不胜感激
set drive=%cd:~0,3%
@echo off
for /F "skip=2 tokens=2 delims=," %%A in ('wmic systemenclosure get serialnumber /FORMAT:csv') do (set "serial=%%A")
mkdir %cd%ProductCodes\%Serial%
wmic path softwarelicensingservice get OA3xOriginalProductKey >> %cd%ProductCodes\%Serial%\Code.txt
wmic computersystem get model,manufacturer >> %cd%ProductCodes\%Serial%\PCINFO.txt
wmic cpu get name >> %cd%ProductCodes\%Serial%\PCINFO.txt
wmic ComputerSystem get TotalPhysicalMemory >> %cd%ProductCodes\%Serial%\PCINFO.txt
wmic diskdrive list full | findstr /B "Size=" >> %cd%ProductCodes\%Serial%\PCINFO.txt
cls
More %cd%ProductCodes\%Serial%\Code.txt
ECHO Open Windows Authentication?
Echo Y/N
SET /P M=Make Choice then press ENTER:
IF %M%==N GOTO :message
IF %M%==n GOTO :message
IF %M%==y GOTO :Start
IF %M%==Y GOTO :Start
:Start
start "C:\Windows\System32" slui.exe 3
pause
:message
CLS
ECHO Done!!
pause
这是我得到的请求输出
厂商型号
惠普 HP ZBook 15 G5
姓名
英特尔(R) 酷睿(TM) i5-8300H CPU @ 2.30GHz
总物理内存
16977272832
枫驱ㄽ㐲ㄱ㈱㤴㈹ര枫驱㈽㘵㔰㤲㘶〴ര
看看这个。我做了很多更改,尤其是您访问 wmic
输出格式的方式。我还使用 choice
而不是一堆 if
语句。
@echo off
for /f "tokens=2 delims==" %%A in ('wmic systemenclosure get serialnumber /FORMAT:list') do mkdir "%~dp0\ProductCodes\%Serial%" >nul 2>&1
for /f "tokens=2delims==" %%i in ('wmic path softwarelicensingservice get OA3xOriginalProductKey /format:list') do (echo %%i)>"%~dp0\ProductCodes\%Serial%\code.txt"
(wmic computersystem get model,manufacturer
wmic cpu get name
wmic ComputerSystem get TotalPhysicalMemory
wmic diskdrive get size
)> "%~dp0\ProductCodes\%Serial%\PCINFO.txt"
cls
More "ProductCodes\%Serial%\code.txt"
ECHO Open Windows Authentication?
choice /m "Open Authentication?"
if errorlevel 2 goto :message
goto :eof
:Start
start "C:\Windows\System32" slui.exe 3
pause
:message
cls
ECHO Done!!
pause
原始 if %m%==y
陈述的旁注。您可以使用 if /i
使匹配不区分大小写。换句话说,if /i "y"=="Y"
也为真,但如果使用 choice
.
则此处不再相关
您可以尝试通过管道命令 More
进行此修改,因为 WMIC
的输出是 UNICODE
@echo off
@for /F "skip=2 tokens=2 delims=," %%A in (
'wmic systemenclosure get serialnumber /FORMAT:csv'
) do (set "serial=%%A")
Set "LogFolder=%cd%ProductCodes\%Serial%"
MkDir "%LogFolder%">nul 2>&1
Set "Code=%LogFolder%\Code.txt"
Set "PCINFO=%LogFolder%\PCINFO.txt"
wmic path softwarelicensingservice get OA3xOriginalProductKey>"%code%"
(
wmic computersystem get model,manufacturer
wmic cpu get name
wmic ComputerSystem get TotalPhysicalMemory
wmic diskdrive list full ^| findstr /B "Size="
) | More>"%PCINFO%"
More "%Code%"
ECHO Open Windows Authentication?
Echo Y/N
SET /P M=Make Choice then press ENTER:
IF /I %M%==N GOTO :message
IF /I %M%==Y GOTO :Start
:Start
start "C:\Windows\System32" slui.exe 3
pause
:message
CLS
ECHO Done!!
pause
我的脚本有问题。我会post它。 它运行良好,直到到达这条线:
wmic diskdrive list full | findstr /B "Size=" >> %cd%ProductCodes\%Serial%\PCINFO.txt
这是它发送到文件的内容... 枫驱ㄽ㐲ㄱ㈱㤴㈹ര枫驱㈽㘵㔰㤲㘶〴ര
如有任何帮助,我们将不胜感激
set drive=%cd:~0,3%
@echo off
for /F "skip=2 tokens=2 delims=," %%A in ('wmic systemenclosure get serialnumber /FORMAT:csv') do (set "serial=%%A")
mkdir %cd%ProductCodes\%Serial%
wmic path softwarelicensingservice get OA3xOriginalProductKey >> %cd%ProductCodes\%Serial%\Code.txt
wmic computersystem get model,manufacturer >> %cd%ProductCodes\%Serial%\PCINFO.txt
wmic cpu get name >> %cd%ProductCodes\%Serial%\PCINFO.txt
wmic ComputerSystem get TotalPhysicalMemory >> %cd%ProductCodes\%Serial%\PCINFO.txt
wmic diskdrive list full | findstr /B "Size=" >> %cd%ProductCodes\%Serial%\PCINFO.txt
cls
More %cd%ProductCodes\%Serial%\Code.txt
ECHO Open Windows Authentication?
Echo Y/N
SET /P M=Make Choice then press ENTER:
IF %M%==N GOTO :message
IF %M%==n GOTO :message
IF %M%==y GOTO :Start
IF %M%==Y GOTO :Start
:Start
start "C:\Windows\System32" slui.exe 3
pause
:message
CLS
ECHO Done!!
pause
这是我得到的请求输出
厂商型号
惠普 HP ZBook 15 G5
姓名
英特尔(R) 酷睿(TM) i5-8300H CPU @ 2.30GHz
总物理内存
16977272832
枫驱ㄽ㐲ㄱ㈱㤴㈹ര枫驱㈽㘵㔰㤲㘶〴ര
看看这个。我做了很多更改,尤其是您访问 wmic
输出格式的方式。我还使用 choice
而不是一堆 if
语句。
@echo off
for /f "tokens=2 delims==" %%A in ('wmic systemenclosure get serialnumber /FORMAT:list') do mkdir "%~dp0\ProductCodes\%Serial%" >nul 2>&1
for /f "tokens=2delims==" %%i in ('wmic path softwarelicensingservice get OA3xOriginalProductKey /format:list') do (echo %%i)>"%~dp0\ProductCodes\%Serial%\code.txt"
(wmic computersystem get model,manufacturer
wmic cpu get name
wmic ComputerSystem get TotalPhysicalMemory
wmic diskdrive get size
)> "%~dp0\ProductCodes\%Serial%\PCINFO.txt"
cls
More "ProductCodes\%Serial%\code.txt"
ECHO Open Windows Authentication?
choice /m "Open Authentication?"
if errorlevel 2 goto :message
goto :eof
:Start
start "C:\Windows\System32" slui.exe 3
pause
:message
cls
ECHO Done!!
pause
原始 if %m%==y
陈述的旁注。您可以使用 if /i
使匹配不区分大小写。换句话说,if /i "y"=="Y"
也为真,但如果使用 choice
.
您可以尝试通过管道命令 More
进行此修改,因为 WMIC
的输出是 UNICODE
@echo off
@for /F "skip=2 tokens=2 delims=," %%A in (
'wmic systemenclosure get serialnumber /FORMAT:csv'
) do (set "serial=%%A")
Set "LogFolder=%cd%ProductCodes\%Serial%"
MkDir "%LogFolder%">nul 2>&1
Set "Code=%LogFolder%\Code.txt"
Set "PCINFO=%LogFolder%\PCINFO.txt"
wmic path softwarelicensingservice get OA3xOriginalProductKey>"%code%"
(
wmic computersystem get model,manufacturer
wmic cpu get name
wmic ComputerSystem get TotalPhysicalMemory
wmic diskdrive list full ^| findstr /B "Size="
) | More>"%PCINFO%"
More "%Code%"
ECHO Open Windows Authentication?
Echo Y/N
SET /P M=Make Choice then press ENTER:
IF /I %M%==N GOTO :message
IF /I %M%==Y GOTO :Start
:Start
start "C:\Windows\System32" slui.exe 3
pause
:message
CLS
ECHO Done!!
pause