关闭命令行和消息问题

时间:2016-04-02 01:12:49

标签: batch-file

    set /p RESTART= WOULD YOU LIKE TO RESTART YOUR COMPUTER NOW?(Y/N):
    echo.    

if %RESTART%==Y  (
              echo.
              echo.
              echo YOUR COMPUTER WILL BE REBOOTED IN 30 SECONDS!!!
              shutdown.exe /r /t 30
              goto Ryes
              ) else (
                  echo.
                  echo.
                  echo YOU CHOSE NOT TO RESTART YOUR COMPUTER.
                  echo.
                  echo *****REMEMBER THAT YOU STILL NEED TO RESTART YOUR COMPUTER SO THE CHANGES CAN BE APPLIED! *****
                    )

    :Ryes
    echo.
    set /p ABORT= WOULD YOU LIKE TO ABORT THE REBOOT?(Y/N):
    echo.

    :A
    shutdown /a

    pause
如果输入Y,

消息“你没有重新启动你的计算机”仍会出现。

Shutdown命令不起作用,我正在以管理员身份运行.bat。 尝试过Windows XP和最新的Windows版本。

我输入的不是Y.但我不认为这是问题,因为其他用户输入选择的工作只是大小写。 两个关机命令:

shutdown -r -f -t 30
shutdown.exe /r /t 30

我知道,因为我在尝试使用Abort选项时收到此消息:

Unable to abort the system shutdown because no shutdown was in progress.(1116)
Press any key to continue . . .

我的批处理文件有什么问题?

感谢您的所有帮助和时间。

2 个答案:

答案 0 :(得分:1)

有关 IF

的详细信息

你应该修改这一行: if %RESTART%==Y到这一行 If /I "%RESTART%"=="Y"

  

/ I做一个不敏感的字符串比较。

@echo off
set /p RESTART= WOULD YOU LIKE TO RESTART YOUR COMPUTER NOW?(Y/N):
echo.    
If /I "%RESTART%"=="Y"  (
    echo.
    echo.
    echo YOUR COMPUTER WILL BE REBOOTED IN 30 SECONDS!!!
    shutdown.exe /r /t 30
    goto Ryes
    ) else (
    echo.
    echo.
    echo YOU CHOSE NOT TO RESTART YOUR COMPUTER.
    echo.
    echo *****REMEMBER THAT YOU STILL NEED TO RESTART YOUR COMPUTER SO THE CHANGES CAN BE APPLIED! *****
)
pause

答案 1 :(得分:0)

在检查RESRART变量是否定义为Y

之前添加此项
if %RESTART%==y set restart=Y