Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal
- rem create a 100ms delayer/timeout vbscript
- >"%temp%\delay.vbs" echo wsh.sleep 100
- rem create prompter batch file. input will be put into a file
- >"%temp%\ask.bat" echo @echo off
- >>"%temp%\ask.bat" echo set/p "inp=Enter input within about 10 seconds: "
- >>"%temp%\ask.bat" echo if "%%inp%%" == "" (
- >>"%temp%\ask.bat" echo ^>"%temp%\input.tmp" rem.
- >>"%temp%\ask.bat" echo ) else (
- >>"%temp%\ask.bat" echo ^>"%temp%\input.tmp" echo %%inp%%
- >>"%temp%\ask.bat" echo )
- rem run prompter in separate process but in current console window
- 2>nul del "%temp%\input.tmp"
- set id=%random%%random%%random%
- start /b cmd.exe /c "%temp%\ask.bat" %id%
- rem set timeout duration to 10 seconds (100 * 100ms)
- set t=100
- :chk
- rem answer file exist?
- if not exist "%temp%\input.tmp" (
- rem still has time to wait?
- if %t% gtr 0 (
- rem generate 1 second delay
- cscript //nologo "%temp%\delay.vbs"
- rem decrease time to wait
- set/a t-=1
- rem check again
- goto chk
- ) else (
- rem no more time to wait
- echo.
- echo timed out.
- rem terminate prompter process
- wmic process where 'commandline like "%%%id%"' call terminate>nul 2>&1
- rem all done
- goto end
- )
- )
- rem get and display input
- set inp=
- for /f "usebackq delims=" %%A in ("%temp%\input.tmp") do set "inp=%%A"
- call echo Enterred input: %inp%
- :end
- rem cleanup
- 2>nul del "%temp%\input.tmp"
- del "%temp%\ask.bat"
- del "%temp%\delay.vbs"
Add Comment
Please, Sign In to add comment