【问题标题】:batch - simple shutdown script批处理 - 简单的关机脚本
【发布时间】:2013-12-20 16:37:43
【问题描述】:

我想编写一个简单的批处理脚本来关闭我自己的计算机,当我在床上看 DVD 或其他东西时将使用它。

更新:修复了代码,还有其他建议吗?

setlocal
@echo off & break off
:input
set /p "minutes=Enter number of minutes to wait until shutdown: "
set "numcheck="&for /f "delims=0123456789" %%i in ("%minutes%") do set "numcheck=%%i"""
if defined numcheck (
    echo ERROR: Sorry "%minutes%" is not numeric, please try again & echo.
    goto input
)
if %minutes% gtr 315360000 (
    echo ERROR: Sorry your input is greater then 10 years, I can't handle that & echo.
    goto input
)
set /a "seconds=%minutes%*60"
shutdown.exe /s /f /t "%seconds%"
if errorlevel 1 (
    echo ERROR: Could not set shutdown, try again & echo.
    goto input
)
:abort
set /p "continue=Your computer is about to shutdown in %minutes% minutes, do you want to abort? (yes/no): "
if %continue% equ yes (
    echo Aborting...
    shutdown.exe /a
    if errorlevel 1 (
        echo ERROR: Could not stop shutdown, try again & echo.
        goto abort
    )
    timeout.exe /t 5 /NOBREAK
    endlocal
    exit /b
) else (
    timeout.exe /t 10 /NOBREAK
    endlocal
    exit /b
)

【问题讨论】:

  • 您是否收到错误,或者为什么它不起作用?
  • 我在此处发布 1 分钟后自己修复了它。大声笑,无论如何我会更新上面的代码,也许你们还有其他建议;)
  • 你遇到了什么错误?
  • && 用于检查错误级别。 & 分隔命令。
  • thx foxidrive,我更新了代码

标签: windows batch-file windows-8 shutdown


【解决方案1】:

使用shutdown 命令的最常用方法是:

  • shutdown -s — 关闭。

  • shutdown -r — 重新启动。

  • shutdown -l — 注销。

  • shutdown -h — 休眠。

    注意: 有一个常见的陷阱,用户认为-h 表示“帮助”(它适用于所有其他命令行程序...除了shutdown.exe,它的意思是“休眠”)。然后他们运行shutdown -h 并意外关闭了他们的计算机。请注意这一点。

  • shutdown -i — “交互模式”。它不执行操作,而是显示一个 GUI 对话框。

  • shutdown -a — 中止之前的关机命令。

以上命令可以与这些附加选项结合使用:

  • -f — 强制程序退出。防止关机进程卡住。

  • -t <seconds> — 设置关机前的时间。使用-t 0 立即关机。

  • -c <message> — 添加关闭消息。该消息将在事件日志中结束。

  • -y — 对所有关闭查询强制回答“是”。

    注意:此选项未记录在任何官方文档中。被these StackOverflow users发现。


我想确保与这个答案一起提到其他一些非常好的答案。在这里它们没有特定的顺序。

【讨论】:

    【解决方案2】:

    关机 -s -t100 使用 .bat 扩展名保存它 100 秒后关机

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-26
      • 2011-10-20
      • 1970-01-01
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多