小编lbr*_*tdy的帖子

批处理文件'choice'命令的errorlevel返回0

我正在尝试创建一个批处理文件,根据正在执行的Windows版本执行不同的"选择"命令.Windows 7和Windows XP之间的选择命令语法不同.

Choice命令为Y返回1,为N返回2.以下命令返回正确的错误级别:

Windows 7的:

choice /t 5 /d Y /m "Do you want to automatically shutdown the computer afterwards "
echo %errorlevel%
if '%errorlevel%'=='1' set Shutdown=T
if '%errorlevel%'=='2' set Shutdown=F
Run Code Online (Sandbox Code Playgroud)

Windows XP:

choice /t:Y,5 "Do you want to automatically shutdown the computer afterwards "
echo %ERRORLEVEL%
if '%ERRORLEVEL%'=='1' set Shutdown=T
if '%ERRORLEVEL%'=='2' set Shutdown=F
Run Code Online (Sandbox Code Playgroud)

但是,当它与检测Windows操作系统版本的命令结合使用时,errorlevel在我的Windows XP和Windows 7代码块中的选择命令之后的AN之前返回0.

REM Windows XP
ver | findstr /i "5\.1\." > nul
if '%errorlevel%'=='0' (
set errorlevel=''
echo %errorlevel%
choice /t:Y,5 "Do you …
Run Code Online (Sandbox Code Playgroud)

command file batch-file choice errorlevel

7
推荐指数
1
解决办法
9046
查看次数

批处理文件第三个“If NOT”语句未达到

你好,stackoverflow 社区,

我正在编写一个批处理文件来进行一些自动计算机维护,并且包含了几个防病毒应用程序。出于某种原因,永远不会达到第三个“如果不是”语句。

:AV
REM MSE
if not '%MSE%'=='' (
Echo Scanning for viruses using Microsoft Security Essentials.
Echo.
%MSE% -Scan -ScanType 1
Echo.
GOTO Defrag
)

REM AVG
if not '%AVG%'=='' (
Echo Scanning for viruses using AVG.
Echo.
%AVG% /COMP /QT /TRASH
Echo.
GOTO Defrag
)

REM NOD32
if not '%NOD32%'==''(
Echo Scanning for viruses using NOD32.
Echo.
if '%NOD32%'=='' GOTO NOD32NotFound
%NOD32% /aind /auto /log-file="%userprofile%\Desktop\Scan_Results.txt"
Echo.
GOTO Defrag
)

REM If all else fails...
GOTO AVNotFound
Run Code Online (Sandbox Code Playgroud)

目前,有三个代码块,每个防病毒程序一个。仅当变量 …

if-statement file batch-file

5
推荐指数
1
解决办法
4万
查看次数

标签 统计

batch-file ×2

file ×2

choice ×1

command ×1

errorlevel ×1

if-statement ×1