4

我遇到了脚本问题。我会发布它。它运行良好,直到到达这一行:

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

这是它发送到文件的内容......枫驱动ㄽ㐲ㄱ㈱㤴㈹ര਍枫驱动㈽㘵㔰㤲㘶〴ര਍</p>

任何帮助,将不胜感激

    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 HP ZBook 15 G5
名称
Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
TotalPhysicalMemory
16977272832
枫驱动ㄽ㐲ㄱ㈱㤴㈹ര਍枫驱动㈽㘵㔰㤲㘶〴ര਍</p>

4

2 回答 2

2

看看这个。我做了很多更改,尤其是您访问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.

于 2021-03-09T20:53:06.307 回答
1

您可以尝试使用管道命令进行此修改,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
于 2021-03-09T21:04:24.110 回答