【问题标题】:BAT Shutdown with countdown delayBAT 关机并有倒计时延迟
【发布时间】:2014-01-16 08:50:33
【问题描述】:

Windows 7 CMD.exe 样式批处理

我不确定这是否能完美运行。我觉得有时 TIMEOUT 完成并且蝙蝠自己执行 SHUTDOWN -ABORT。我希望用户只需按一个键即可停止关机倒计时(理想情况下,只需 COMMENT “OK”按钮就足够了),否则可以完美关闭计算机。

if exist "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" ("C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 vlc://quit) else goto end
shutdown -s -t 120 -c "Press any key in the Command Prompt to cancel the shutdown."
timeout -t 120
shutdown -a

我考虑添加 PING 999.999.999.999 -n 1 -w 1000 来强制短暂等待,但如果用户按下某个键,那么它会在中止关机之前等待,这也可能导致问题。

【问题讨论】:

  • 将此start "C:\Program Files\GlovePIE045Free\piefree.exe" 更改为start "" "C:\Program Files\GlovePIE045Free\piefree.exe",因为第一个引用的术语用作窗口标题。然后将"" 用作空标题。
  • 是的,我试过 start "" "C:\Program Files\GlovePIE045Free\piefree.exe" -"C:\Program Files\GlovePIE045Free\CustomScripts\xbox360VLCremote.PIE" /tray 但它返回 [-"C:\Program is not a valid program]
  • 等等,我刚试了一下,它运行了两个程序(耶),但 VLC 没有制作播放列表,只运行用于拖动整个文件的文件。
  • piefree 是做什么的?
  • 我发现它是一种使用我的无线控制器来命令 VLC 的方法。 (code.google.com/p/xbox-360-vlc-remote)

标签: batch-file countdown shutdown


【解决方案1】:

这使用Choice 提供延迟和要检查的错误级别,以便在按下 C 时中止。它还提供了一个额外的选项来立即关闭。

超时不提供中止的错误级别,因此按任意键中止似乎不是一个选项。

@echo off
if exist "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" ("C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 vlc://quit) else (goto :EOF)
choice /c CS /D S /T 120 /M "Waiting for 120 seconds: Press C to cancel shutdown, or S to shutdown now"
if errorlevel 2 shutdown -s

【讨论】:

  • 不管用户是否按下任何键,这不会在 120 秒后关闭吗?
  • 这很好用,谢谢。我在看到这个之前编辑了我的帖子,无法添加另一个程序来启动。
【解决方案2】:

考虑使用choice command。您可能需要下载它,具体取决于您的操作系统。

如果未按下q,这将在关闭前等待 300 秒。

choice /c aq /n /d a /t 300 /m "Computer shutting down in 300 seconds [q to cancel]"
if %errorLevel%==1 shutdown -a

【讨论】:

  • 没问题 - 您能否将其中一个答案标记为正确,这样这个问题就不会保持开放?
  • 对此很抱歉,希望能得到其他问题的答复,我把它作为自己的问题。 stackoverflow.com/questions/21151408/…
猜你喜欢
  • 2019-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-01
  • 1970-01-01
相关资源
最近更新 更多