Batch Script is exporting weird characters

Viewed 103

I am having an issue with a script. I will post it. It runs fine till it gets to this line:

wmic diskdrive list full | findstr /B "Size=" >> %cd%ProductCodes\%Serial%\PCINFO.txt

This is what it sends to the file... 楓敺ㄽ㐲ㄱ㈱㤴㈹ര਍楓敺㈽㘵㔰㤲㘶〴ര਍

Any help would be appreciated

    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

Here is the requested output I get

Manufacturer Model
HP HP ZBook 15 G5
Name
Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
TotalPhysicalMemory
16977272832
楓敺ㄽ㐲ㄱ㈱㤴㈹ര਍楓敺㈽㘵㔰㤲㘶〴ര਍

2 Answers

Have a look at this. I made quite a few changes, especially the way you accessed the format of wmic output formats. I also used choice instead of a bunch of if statements.

@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

Side note on your original if %m%==y statements. You can use if /i to make the match case insensitive.. in other words, if /i "y"=="Y" will be true as well, but no longer relevant here if using choice.

You can give a try for this modification with piping the command More since the output of WMIC is 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
Related