
[探討]批處理代碼特殊字符沖突事件批處理代碼文件是ANSI格式,在Win11 23H2系統下顯示是正常的ANSI編碼,但是在24H2或者最新版本的記事本中顯示為UTF-8,且中文內容全部為亂碼,修改文件只能用第三方軟件修改。經過反復嘗試刪減和測試,發現只要刪除下面3行內容的任意一行即可解決,有沒有大佬能看出問題所在,還請解答一下造成問題的原因:if %today% GTR 2030 (date -12-12)::===========BIOSDATESET==============::===========BIOSDATESET==============之前有一段代碼在AMD處理器搭配銘瑄B450主板,會出現不執行的情況,后面也是修改了代碼語句才可以正常使用。當時懷疑是CPU指令集出錯導致的,但是找不到驗證辦法。下面是全部代碼:
nload="thumbImg(this)" alt="" />nclick="copycode($('code0'));">復制代碼
- @echo off & setlocal enabledelayedexpansion
- set today=%date:~0,4%
- if %today% GTR 2030 (date -12-12)
- ::===========BIOSDATESET==============
- for /f tokens=1-3 delims=/ %%a in ('echo %date%') do (
- set sysdate_y=%%a
- set sysdate_m=%%b
- set sysdate_d=%%c
- set sysdate_y=!sysdate_y: =!
- set sysdate_m=!sysdate_m: =!
- set sysdate_d=!sysdate_d: =!
- )
- call C:intel10cpuz_x64.exe -txt=1
- for /f tokens=1,2 %%a in ('type C:intel101.txt ^|find /i date ^|find /i / ^|find /i /') do (
- if %%a equ date set biosdate=%%b
- )
- for /f tokens=1-3 %%a in ('type C:intel101.txt ^|find /i speed ^|find /i MHz') do (
- if %%a equ speed set MemorySpeed=%%b%%c
- )
- for /f tokens=1-3 delims=/ %%a in ('echo !biosdate!') do (
- set biosdate=%%c/%%a/%%b
- set biosdate_y=%%c
- set biosdate_m=%%a
- set biosdate_d=%%b
- set biosdate_y=!biosdate_y: =!
- set biosdate_m=!biosdate_m: =!
- set biosdate_d=!biosdate_d: =!
- )
- echo,!sysdate_y!
- echo,!biosdate_y!
- if !sysdate_y! gtr !biosdate_y! (set biosdate=!biosdate!_需刷BIOS)
- if !sysdate_y! equ !biosdate_y! (if !biosdate_m! lss 08 (set biosdate=!biosdate!_需刷BIOS))
- set textFile=C:Intel11Home_Log.txt
- call C:intel10sed.exe -i s#Update=BIOSDATE#Update=!biosdate!#g %textFile%
- call C:intel10sed.exe -i -i s#_需刷BIOS##g %textFile%
- call C:intel10sed.exe -i s#([0-9]{4}/[0-9]{2}/[0-9]{2})#%biosdate%#g %textFile%
- ::===========BIOSDATESET==============
- Start /min C:intel10Motherboardinfo.exe
- ::for /f tokens=3 delims=, %%a in ('echo ^|pnputil /enum-devices /disconnected ^|find 實例 ID:') do echo 移除設備:%%a & pnputil /remove-device %%a >nul
- if exist C:OA3.BIn (goto End)
- cls
- Start /min C:Intel10infoC-D.bat
- for %%d in (E F G H I J K L M N O P Q R S T U V W X Y Z) do (if exist %%d:Autorun.inf (if exist %%d:Setup.exe (call %%d:Setup.exe) ))
- for /f tokens=* delims=, %%a in ('powershell -Command Get-NetAdapter | Select-Object -ExpandProperty InterfaceDescription ^|find /i Realtek 8811CU Wireless LAN 802.11ac USB NIC') do set U9=%%a
- for /f tokens=* delims=, %%a in ('powershell -Command Get-NetAdapter | Select-Object -ExpandProperty InterfaceDescription ^|find /i Realtek RTL8192EU Wireless LAN 802.11n USB 2.0 Network Adapter') do set U3=%%a
- if defined U9 (
- echo 存在無線網卡設備U9
- netsh wlan add profile filename=C:RWorker_TestPwork_1_5G.xml
- netsh wlan set profileparameter name=Pwork_1_5G connectionmode=auto
- )
- if defined U3 (
- echo 存在無線網卡設備U3
- netsh wlan add profile filename=C:RWorker_TestPwork_1_2G.xml
- netsh wlan set profileparameter name=Pwork_1_2G connectionmode=auto
- )
- if not defined U9 (
- if not defined U3 (
- echo 不存在無線網卡設備
- )
- )
- :LSXCE
- ::==========================自動化線體測試過程==========================
- for /f tokens=2*delims=:^ %%a in ('echo ^|C:Intel10WIN10ACTIVEUUDI-KEYnwinfo_x64.exe --smbios ^|find UUID:') do set UUID0=%%a
- IF %UUID0%==00020003-0004-0005-0006-000700080009 (C:Intel10WIN10ACTIVEUUDI-KEYAMIDEWINx64.exe /SUauto)
- IF %UUID0%==FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF (C:Intel10WIN10ACTIVEUUDI-KEYAMIDEWINx64.exe /SUauto)
- for /f tokens=2*delims=:^ %%b in ('echo ^|C:Intel10WIN10ACTIVEUUDI-KEYnwinfo_x64.exe --smbios ^|find UUID:') do set UUID1=%%b
- if not %UUID0%==%UUID1% (
- echo %UUID0% >C:Intel10UUID.dll
- echo %UUID1% >>C:Intel10UUID.dll
- echo %date% %time%主板SMBIOS_UUID刷寫完成,即將重啟系統。
- echo %date% %time%主板SMBIOS_UUID刷寫完成。 >>C:Intel10UUID.dll
- shutdown /r /t 2
- PAUSE
- )
- cd /d C:RWorker_Test
- Start RWorker.exe
- timeout -t 4 >nul
- Start C:Intel10sinfo.exe
- echo,[系統運行狀態] >C:Intel10sinfo.ini
- set count=0
- set file=run_count.txt
- if exist %file% (
- set /p count=<%file%
- )
- set /a count+=1
- echo %count% > %file%
- if %count% gtr 1 (
- echo,警告:這個腳本已經運行了 %count% 次.
- ) >>C:Intel10sinfo.ini
- (
- echo,內存運行頻率:!MemorySpeed!
- echo.
- ) >>C:Intel10sinfo.ini
- :loop
- timeout -t 2 >nul
- ping -t -n 1 172.17.2.250
- if errorlevel 1 goto loop
- if errorlevel 0 goto yes
- :yes
- cls
- if exist C:DumpStack.log (echo 主機出現過異常重啟:C:DumpStack.log) >>C:Intel10sinfo.ini
- if exist C:WindowsMinidump (
- set count=0
- for /f tokens=* %%a in ('dir /b /a - d C:WindowsMinidump*.dmp 2^>nul') do (
- set /a count+=1
- )
- echo,藍屏記錄!count!個文件如下:
- for /f tokens=* delims=, %%b in ('dir /a /s /b C:WindowsMinidump*.* ') do echo %%b
- echo.
- ) >>C:Intel10sinfo.ini
- :End
- exit

