键入密码时批处理文件取消超时

时间:2017-03-21 21:36:01

标签: batch-file

我不知道如何在键入密码时取消超时。它也不会显示,直到我在那时点击输入计算机因为事件而退出

Map ginormousMap = extractMapFromFile()
(ginormousMap.size()/100).times { i ->
       sendToFragileBackEnd(ginormousMap[i*100..(i+1)*100-1)
}

1 个答案:

答案 0 :(得分:3)

它最初出现时有点困难。我评论了所有内容,但如果您有任何问题请与我联系。

@echo off

pause

REM We need to start the timer and shutdown in a separate window because batch
REM can't do multiple things at once. Also, we're starting the second window
REM minimized mostly for aesthetics, but also to reduce the chance of the user
REM pressing a key by accident and killing the timer without diffusing the stop.
REM
REM The /t 10 waits 10 seconds before shutting the computer down. Unfortunately,
REM the /l option to log out does not allow the /t switch to be used. This adds
REM a bigger element of danger, anyway. The way the code works, you'll still get
REM a pop-up that says that Windows is shutting down in less than a minute, but
REM the shutdown will be aborted.
start "" /min cmd /c "timeout 60&shutdown /s /t 10"

:LOGIN
echo Enter the password to stop the timer!

REM I moved the left quote to the left of pass so that quotes would still be in
REM effect but they wouldn't be visible. I also removed the space between pass
REM and the = because the way it was before, you had a variable that would have
REM to be accessed as %pass % because you can put spaces in variable names for
REM some reason.
set /p "pass=Password: "

REM I've put quotes around both %pass% and Password to prevent a syntax error
REM that would occur if the user didn't enter anything. Also, I got rid of the
REM space to the left of Password because the way it was originally written,
REM the password would have been <space>Password and I wasn't sure if that was
REM deliberate. If it was, just add it back in.
if not "%pass%"=="Password" (
    echo Incorrect password! Please try again!
    goto :LOGIN
) else (
    echo CORRECT!

    REM Thankfully, the timeout command is a separate executable from the rest
    REM of CMD, so we can just simply kill it. Note that if you have any other
    REM timeouts running, this will kill them as well. The >nul is to prevent
    REM a "The process timeout.exe with PID 12345 has been terminated" message.
    taskkill /F /IM timeout.exe >nul

    REM I've added a one-second(-ish) pause between aborting the timeout and
    REM aborting the shutdown so that the shutdown command actually has a
    REM chance to start. Otherwise, there's a race condition where the abort
    REM might run before the shutdown is triggered and that would be really bad.
    ping 127.0.0.1 -n 2 >nul

    REM This just aborts the shutdown command.
    shutdown /a
)