【发布时间】:2015-01-02 14:52:46
【问题描述】:
我正在尝试创建一个批处理文件,该批处理文件将在系统激活和注销时进行倒计时。这适用于用户不再在计算机旁的情况。我遇到过多个论坛,人们正在这样做,但只要用户空闲 x 分钟或秒,他们就会注销。我所拥有的确实倒计时并注销或取消,并且我在任务计划程序中将其设置为在计算机空闲时启动。那部分工作正常。我似乎无法正常工作的是,如果时间在下午 6:30(18:30)之后才执行倒计时。它对我有用过一次,但我不能再让它工作了。
所以我需要更具体的顺序。
- 需要检查时间以确保在下午 6:30 之后
- 如果时间还没有到下午 6:30 且没有用户交互,则需要退出。
- 如果时间在下午 6:30 之后,则开始注销序列
到目前为止,以下内容似乎运行良好。
- 按任意字母键取消序列
- 如果序列未取消,则强制注销
这是我现在可以运行的代码,它只是不关心现在是什么时间。
TITLE Automatic Log Off Initiated!
mode con:cols=80 lines=1
COLOR CF
@echo off
setlocal enableextensions enabledelayedexpansion
set tm=%time%
:: Test data on lines below.
:: set tm=18:59:59.00
:: set tm=19:00:00.00
:: set tm=19:44:59.00
:: set tm=19:45:00.00
:: set tm=23:59:59.99
set hh=!tm:~0,2!
set mm=!tm:~3,2!
if !hh! LEQ 18 if !mm! LEQ 30 (
exit
)
else goto :begin
:begin
for /l %%N in (600 -1 1) do (
set /a "min=%%N/60, sec=%%N%%60, n-=1"
if !sec! lss 10 set sec=0!sec!
cls
choice /c:1ABCDEFGHIJKLMNOPQRSTUVWXYZ /n /m "Automatically Logging Off in !min!:!sec! - Press any key or move the mouse to cancel" /t 1 /d 1
if not errorlevel 1 goto :break
if errorlevel 2 goto :end
if errorlevel 3 goto :end
if errorlevel 4 goto :end
if errorlevel 5 goto :end
if errorlevel 6 goto :end
if errorlevel 7 goto :end
if errorlevel 8 goto :end
if errorlevel 9 goto :end
if errorlevel 10 goto :end
if errorlevel 11 goto :end
if errorlevel 12 goto :end
if errorlevel 13 goto :end
if errorlevel 14 goto :end
if errorlevel 15 goto :end
if errorlevel 16 goto :end
if errorlevel 17 goto :end
if errorlevel 18 goto :end
if errorlevel 19 goto :end
if errorlevel 20 goto :end
if errorlevel 21 goto :end
if errorlevel 22 goto :end
if errorlevel 23 goto :end
if errorlevel 24 goto :end
if errorlevel 25 goto :end
if errorlevel 26 goto :end
if errorlevel 27 goto :end
)
:break
shutdown /l /f
:end
exit
我用它来测试不同时间的时间,但它仍然不起作用。
我也尝试过使用第二个 IF 语句,但没有奏效。
IF !hh! GTR 18 IF !mm! GTR 30 (
goto :begin
)
非常感谢任何帮助!谢谢!
【问题讨论】:
标签: batch-file cmd logoff