找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 1386|回复: 6

[其他] [已解决]奇怪的批处理,不让加汉字,加了汉字就运行不正常

[复制链接]
发表于 2025-10-29 21:55:51 | 显示全部楼层 |阅读模式
本帖最后由 hnfeng 于 2025-10-30 14:57 编辑

这个批处理,我想把一些英文信息文字改为汉字,结果发现只要有汉字,批处理就运行不正常。怎么做到的?如何去掉这个限制?
原批处理是ansi编码
  1. @echo off

  2. rem script:                @rgadguard
  3. rem version:        v1.03.2

  4. setlocal EnableExtensions
  5. setlocal EnableDelayedExpansion

  6. color 0a

  7. :BIN
  8. cd /d "%~dp0"
  9. if exist "%~dp0bin\7z.exe" (set "x7z=%~dp0bin\7z.exe") else (goto :DLBin)
  10. if not exist "%~dp0bin\7z.cmd" goto :DLBin
  11. if not exist "%~dp0bin\7z.dll" goto :DLBin
  12. if exist "%~dp0bin\aria2c.exe" (set "aria2=%~dp0bin\aria2c.exe") else (goto :DLBin)
  13. if not exist "%~dp0bin\smv.cmd" goto :DLBin
  14. if exist "%~dp0bin\smv.exe" (set "smv=%~dp0bin\smv.exe") else (goto :DLBin)

  15. call :sup
  16. call :tr

  17. set "uuid=0ffac4d9-0ec8-80b2-1e75-31f1d0baa24a"
  18. set "key=free"

  19. if /i !key! EQU free call :free
  20. color 0a
  21. title Select list files...

  22. "%aria2%" -x1 -s1 -d"%dir_temp%" -o"list.txt" "https://files.rg-adguard.net/file/%uuid%/list" --disable-ipv6
  23. for /f "tokens=1 delims=" %%a in ('type "%dir_temp%\list.txt"') do set /a count+=1

  24. :ListFiles
  25. cls
  26. set ListSel=
  27. echo.
  28. echo %r%
  29. echo The list of files that will be uploaded during operation...
  30. echo %r%
  31. echo.
  32. for /f "tokens=2,3 delims=^|" %%a in ('type "%dir_temp%\list.txt"') do (
  33.         echo %%a   ^(%%b^)
  34. )
  35. echo.
  36. echo %r%
  37. if /i %count% NEQ 1 (
  38.         echo         Save all files                                - press key S
  39.         echo         Save only the requested file                - press key F
  40. ) else (
  41.         echo        Enter F or S to continue downloading files
  42. )
  43. echo %r%
  44. echo.
  45. CHOICE /c fs /n /m "Save all or just the requested file?"
  46. if /i %count% NEQ 1 (If Errorlevel 2 set ListSel=S)
  47. If Errorlevel 1 set ListSel=F
  48. goto :working

  49. :working
  50. title Download files...
  51. cls
  52. "%aria2%" -x1 -s1 -d"%dir_temp%" -o"dl.txt" "https://files.rg-adguard.net/dl/%key%/%uuid%" --disable-ipv6
  53. "%aria2%" -x1 -s1 -j1 -c -R -d"%cd%" -i"%dir_temp%\dl.txt" --disable-ipv6
  54. if exist "%~dp0tmp\*.aria2" (
  55.     erase /q "%dir_temp%\dl.txt"
  56.     echo Re-download, after 10 seconds...
  57.     timeout /t 10 /NOBREAK
  58.         goto :working
  59. )
  60. call bin\7z.cmd
  61. call bin\smv.cmd
  62. goto :exit

  63. :DLBin
  64. for /f "tokens=3 delims=:. " %%f in ('bitsadmin.exe /CREATE /DOWNLOAD "Download Tools" ^| findstr "Created job"') do set GUID=%%f
  65. title Download tools...
  66. bitsadmin /transfer %GUID% /download /priority foreground https://files.rg-adguard.net/tools "%cd%\tools.cab"
  67. if NOT EXIST tools.cab goto :Error 4
  68. expand "tools.cab" -f:* .\ >nul
  69. del /f /q tools.cab >nul 2>&1
  70. goto :BIN

  71. :sup
  72. set "dir_temp=%~dp0%random%"
  73. set xOS=x86
  74. if exist "%WINDIR%\SysWOW64" Set xOS=x64
  75. if exist "%WINDIR%\SysArm32" Set xOS=a64

  76. for /f "tokens=6 delims=[]. " %%# in ('ver') do set xBuild=%%#
  77. if %xOS% NEQ x64 goto :Error 1
  78. if %xBuild% LSS 6000 goto :Error 2
  79. exit /b

  80. :Error
  81. cls
  82. color 4f
  83. echo.
  84. echo %r%
  85. echo.
  86. echo.
  87. if %1==1 echo                      Attention, the script only works with a 64-bit system.
  88. if %1==2 echo           For the script to work, the operating system Windows Vista or higher is required.
  89. if %1==3 echo                            There are not enough files in the bin folder.
  90. if %1==4 echo                               Failed to download the software package.
  91. echo.
  92. echo.
  93. echo %r%
  94. echo.
  95. echo.
  96. pause
  97. exit

  98. :limit
  99. title LIMIT DOWNLOAD
  100. cls
  101. color 4f
  102. echo.
  103. echo %r%
  104. echo.
  105. echo                                                LIMIT DOWNLOAD
  106. echo.
  107. echo                           You have exceeded the limit of simultaneous connections.
  108. echo                      During the free download, no more than 1 connection is available.
  109. echo.
  110. echo %r%
  111. echo.
  112. pause
  113. echo.
  114. exit

  115. :free
  116. title THIS BANNER IS A WARNING
  117. cls
  118. color 4f
  119. echo.
  120. echo %r%
  121. echo.
  122. echo                                           THIS BANNER IS A WARNING
  123. echo.
  124. echo                                      You have used the free download.
  125. echo                                    The download speed will be limited.
  126. echo            If you want to download multiple files at maximum speed and with the possibility
  127. echo                  of downloading them at once, you need to purchase a subscription.
  128. echo.
  129. echo %r%
  130. echo.
  131. echo                              This message is available within a few seconds.
  132. echo.
  133. timeout /t 10 /NOBREAK
  134. echo.
  135. exit /b

  136. :exit
  137. set fnd=n
  138. title Finish...
  139. cls
  140. echo.
  141. echo %r%
  142. echo.
  143. echo                                        The script is finished.
  144. echo                All the files you received are files, you will find them next to the script.
  145. echo.
  146. echo                                      Here is the list of files:
  147. echo %t%
  148. echo.
  149. for /f "tokens=2 delims=^|" %%a in ('type "%dir_temp%\list.txt"') do (
  150.         if exist %%a echo %%a && set "fnd=y"
  151. )
  152. if !fnd! NEQ y goto :limit
  153. echo.
  154. echo %r%
  155. echo.
  156. rd>nul /s /q "%dir_temp%"
  157. timeout>nul /t 10
  158. exit

  159. :tr
  160. set "r=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^=^="
  161. set "t=----------------------------------------------------------------------------------------------------"
  162. goto :eof
复制代码
 楼主| 发表于 2025-10-29 22:00:20 | 显示全部楼层
发表于 2025-10-29 22:26:52 | 显示全部楼层
回复 1# hnfeng

诊断须知》你要修改哪个位置的英文数据?
发表于 2025-10-29 22:56:05 | 显示全部楼层
我的系统win11,22H。
反正是奇奇怪怪的不算正常,可以用。
新建文本是utf-8格式。
新建的bat如果内容是全英文字母,改ansi格式后还是会变为utf-8,处理汉字会出错。所以我是在bat开头先写个汉字,bat就不会变utf-8。比如 echo 啊

楼主的情况也许是这样。可以试试看。
发表于 2025-10-30 00:20:48 | 显示全部楼层
回复 2# hnfeng


   换行符改为CR+LF试试

评分

参与人数 1技术 +1 收起 理由
holley + 1 厉害!

查看全部评分

 楼主| 发表于 2025-10-30 07:32:10 | 显示全部楼层
本帖最后由 hnfeng 于 2025-10-30 08:31 编辑
回复  hnfeng

诊断须知》你要修改哪个位置的英文数据?
aloha20200628 发表于 2025-10-29 22:26


所有位置

    例如,不改动运行正常。如果在118行后面加一个“汉”字,再运行就乱套了。删掉这个“汉”字,再运行,又正常
 楼主| 发表于 2025-10-30 07:38:02 | 显示全部楼层
回复  hnfeng


   换行符改为CR+LF试试
77七 发表于 2025-10-30 00:20



    厉害厉害,一下子点醒梦中人。

经试验,果然是这个原因
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 07:10 , Processed in 0.026536 second(s), 12 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表