批处理脚本导出奇怪的字符 [英] Batch Script is exporting weird characters

查看:59
本文介绍了批处理脚本导出奇怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本有问题.我将发布它.运行良好,直到到达这一行:

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... 楓敺ㄽ㐲ㄱ㈱㤴㈹ര਍楓敺㈽㘵㔰㤲㘶〴ര਍

任何帮助将不胜感激

    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

制造商型号
惠普HP ZBook 15 G5
名称
英特尔®酷睿TM i5-8300H CPU @ 2.30GHz
TotalPhysicalMemory
16977272832
枫驱ㄽ㐲ㄱ㈱㤴㈹ര਍枫驱㈽㘵㔰㤲㘶〴ര਍

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

推荐答案

看看这个.我做了很多更改,尤其是您访问 wmic 输出格式的格式的方式.我还使用了 choice 而不是一堆 if 语句.

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

原始 if%m%== y 语句上的注释.您可以使用 if/i 使区分大小写不敏感..换句话说, if/i"y" =="Y" 也将为真,但如果使用 choice ,则在这里不再相关.

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.

这篇关于批处理脚本导出奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆