为什么我的关机脚本不起作用?

时间:2013-11-01 17:27:38

标签: windows batch-file cmd

我在Windows 8.1上运行它,如果我在没有脚本的情况下运行shutdown命令,它可以工作。但是当我从这个脚本运行它时,cmd中显示了一些错误的语法....感谢您的帮助

@echo off
TITLE shutdown timer

SET /P minutes=Enter minutes till shutdown or "no" to stop running shutdowns: 

IF "%minutes%" == "no" (
    shutdown /a
    echo shutdown aborted
) ELSE (
    SET /A seconds = %minutes% * 60
    shutdown /s /f /t %seconds%
)
pause

2 个答案:

答案 0 :(得分:2)

@echo off &setlocal enabledelayedexpansion
TITLE shutdown timer

SET /P "minutes=Enter minutes till shutdown or "no" to stop running shutdowns: "

IF "%minutes%" == "no" (
    shutdown /a
    echo shutdown aborted
) ELSE (
    SET /A seconds = minutes * 60
    shutdown /s /f /t !seconds!
)

答案 1 :(得分:1)

将秒数移出条件并运行:

@echo off
TITLE shutdown timer

SET /P minutes=Enter minutes till shutdown or "no" to stop running shutdowns:
SET /A seconds = %minutes% * 60

IF "%minutes%" == "no" (
shutdown /a
echo shutdown aborted
) ELSE (
shutdown /s /f /t %seconds%
)
pause