使用带有变量的IF语句

时间:2014-07-25 16:28:57

标签: windows batch-file

很抱歉,如果我问一个非常愚蠢的问题,但是我在编写简单的批处理脚本时有点生疏,但我遇到了一个问题。我想编写一个脚本,根据一周的日期更改本地管理员密码。该脚本运行但只运行第一个标签并跳过IF语句,我对这个问题可能不太确定。

FOR /F "skip=1" %%A IN ('WMIC Path Win32_LocalTime Get DayOfWeek') DO (
  set DOW=%%A
)

IF DOW == 0 goto SUN
IF DOW == 1 goto MON
IF DOW == 2 goto TUE
IF DOW == 3 goto WED
IF DOW == 4 goto THU
IF DOW == 5 goto FRI
IF DOW == 6 goto SAT

:SUN
net user admin Password0
GOTO END

:MON
net user admin Password1
GOTO END

:TUE
net user admin Password2
GOTO END

:WED
net user admin Password3
GOTO END

:THU
net user admin Password4
GOTO END

:FRI
net user admin Password5
GOTO END

:SAT
net user admin Password6
GOTO END

:END

2 个答案:

答案 0 :(得分:2)

要读取DOW变量中的值,语法为%DOW%

if %DOW%==0 goto SUN

答案 1 :(得分:0)

您也可以使用以下内容。另请注意,您需要在标签前添加冒号(:),这似乎在您的代码中缺失。

if %DOW% EQU 0 goto :SUN

干杯,G

相关问题