Hack Forums
[Shell] Would this be possible? User set timer, close, open at timer end - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Would this be possible? User set timer, close, open at timer end (/showthread.php?tid=5099417)



Would this be possible? User set timer, close, open at timer end - Elite Hacker 69 - Dec 18, 2015

I want to make a script that will, on startup, open a web page. After/during that is opening, I want the user to enter a number which will be converted to whatever time unit batch uses and start a timer. Can they then close that window and have the timer still run? I would like for at the end of the timer for it to open another window and then end itself.

Thank you


* - b00st3d - Dec 18, 2015

(Dec 18, 2015 04:21 PM)Haskell Wrote:  I want to make a script that will, on startup, open a web page. After/during that is opening, I want the user to enter a number which will be converted to whatever time unit batch uses and start a timer. Can they then close that window and have the timer still run? I would like for at the end of the timer for it to open another window and then end itself.

Thank you



This is possible. I don't know what window you want to open so I just have it re-opening cmd

Code
@echo off
start www.google.com
call :InputBox "Enter a time to wait" "Time"
echo CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0, False > invisible.vbs
(
echo @echo off
echo timeout /t %input%
echo start
echo exit
) >timer.bat
start invisible.vbs timer.bat
exit


REM Input routine for batch using VBScript to provide input box
REM Stephen Knight, October 2009, http://www.dragon-it.co.uk/
:InputBox
set input=
set heading=%~2
set message=%~1
echo wscript.echo inputbox(WScript.Arguments(0),WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do set input=%%a
exit /b



* - Nakamoto. - Dec 24, 2015

(Dec 18, 2015 05:06 PM)b00st3d Wrote:  This is possible. I don't know what window you want to open so I just have it re-opening cmd

Code
@echo off
start www.google.com
call :InputBox "Enter a time to wait" "Time"
echo CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0, False > invisible.vbs
(
echo @echo off
echo timeout /t %input%
echo start
echo exit
) >timer.bat
start invisible.vbs timer.bat
exit


REM Input routine for batch using VBScript to provide input box
REM Stephen Knight, October 2009, http://www.dragon-it.co.uk/
:InputBox
set input=
set heading=%~2
set message=%~1
echo wscript.echo inputbox(WScript.Arguments(0),WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do set input=%%a
exit /b

batch can do this without the vbscript in it
Code
@echo off
set /p time=Enter how long you want the window open:
:main
    set ctime=%time%
    start yourwebsite.com
    call :time
goto main

:time
    timeout /t 1>nul
    set ctime-=1
    if %ctime%==0 (
        taskkill /IM yourbrowser.exe
        goto :eof
    )
goto time



* - b00st3d - Dec 24, 2015

(Dec 24, 2015 02:37 PM)RenRioku™ Wrote:  batch can do this without the vbscript in it
agreed the vbscript in my example just made it fancy and run invisible.