如果否则循环崩溃批处理文件

时间:2021-02-03 00:57:27

标签: batch-file


for /f "skip=1 tokens=1,2" %%i in ('wmic logicaldisk get caption^, drivetype') do (
  if [%%j]==[5] set cdletter=%%i
  )


echo %cdletter%

pause


if "%cdletter%"=="" (
echo Device driver not found: 'MSCD000'
echo No valid CDROM device drivers selected
) else ( 
echo MSCDEX Version 2.23
echo Copyright (C) Microsoft Corp. 1986-1993. All rights reserved.
pause
echo        "Drive %cdletter% = Driver MSCD000 unit 0"
)


我在它之前也运行了另一个 if else 并且这个工作正常。我不知道为什么另一个不起作用

if "%cdletter%"=="" ( 
timeout 2 >nul
echo    No drives found, aborting installation
) else (

chcp 65001 >nul
wmic cdrom where mediatype!='unknown' get name > discinfo.txt
type discinfo.txt > discinfoutf8.txt 
rem F THIS YOU HAVE TO DO THIS BECASUE UTF 16 DOESNT WORK IN A FOR LOOP 

goto driveinfoecho
)

这只是获取 cd 驱动器信息,所以我可以将它放入一个变量中并在 echo 命令中使用它

1 个答案:

答案 0 :(得分:0)

作为您在评论中收到的建议的替代方案,我建议您完全省略 Else 条件,如果没有 CDROM 或有问题的 CDROM 则关闭脚本.

@Echo Off & SetLocal EnableExtensions
Set "Drive=" & For /F %%G In ('%SystemRoot%\System32\wbem\WMIC.exe Path
 Win32_CDROMDrive Where "ConfigManagerErrorCode=0" Get Drive 2^> NUL'
) Do For /F Tokens^=* %%H In ("%%G") Do Set "Drive=%%H"
If Not Defined Drive (Echo No properly working CDROM drive found
 Echo Press a key to exit . . . & Pause 1> NUL & GoTo :EOF)
Echo MSCDEX Version 2.23
Echo Copyright (C) Microsoft Corp. 1986-1993. All rights reserved.
Pause
Echo        "Drive %Drive% = Driver MSCD000 unit
相关问题