Page 1 of 1

Time limit on CMD window to close

Posted: 04 May 2011 13:35
by MattGillman
Hi,

I have three batch files that link together. The first one, (which asks for a password) triggers the second one, (which runs through random numbers as if it were decoding something) which then triggers the third one (which shows "decoded" information). Here are the codes for all three files:

First one:

:wrong
@echo off
title Rotor Encryption Coding
color 00
cls
echo Enter Password
set /p input= :
IF '%input%' == 'wytuxa' goto menu
goto error
:error
cls
echo Access Denied.
pause nul
goto wrong
:menu
echo Password Correct
start "c:\Users\Matthew\Desktop\-" "c:\Users\Matthew\Desktop\-\Matrix.BAT"


Second one:

@echo off
title System Decryption
set /a counta=1
:start
if %counta% equ 4000 goto end
set /a counta=%counta%+1
color 00
echo %random%%random% %random%%random% %random%%random% %random%%random% %random%%random% %random%%random%
goto start
:end
goto new window
:new window
start "c:\Users\Matthew\Desktop" "c:\Users\Matthew\Desktop\test2.BAT"
pause



Third one:

@echo off
title Decrypted Intelligence
colour 00
cls
echo Decrypted Intelligence: HELP
echo.
echo Please press ANY key to EXIT
pause> nul
:end


'j' goto menu
:menu

it
to exittcho exit

.................................

The problem i have is that when i start the sequence off and it runs through batch file 1, 2 and finally three, i have 3 saying 'press any key to exit' but it doesn't exit when you press any key, it just state my c:\ and then goes to the next line!

How do i fix that?

The Second thing i want to do is put a time limit on the Batch file windows, for example, when batch file 2 opens i want it to automatically close after 20 seconds and when batch file 3 is open i want it to close after 10 seconds.

How do i do this?

Regards

Matt

Re: Time limit on CMD window to close

Posted: 04 May 2011 14:04
by nitt
On new operating systems, usually "timeout /nobreak 5 > nul" will pause the Batch file. But on older systems you may need to use "ping 0 -n 5 > nul". The both will pause or 5 intervals.

Re: Time limit on CMD window to close

Posted: 04 May 2011 14:06
by MattGillman
nitt wrote:On new operating systems, usually "timeout /nobreak 5 > nul" will pause the Batch file. But on older systems you may need to use "ping 0 -n 5 > nul". The both will pause or 5 intervals.


but pausing the process isnt going to close the window though, is it?

Sorry, what question are you replying to?

Re: Time limit on CMD window to close

Posted: 04 May 2011 14:11
by nitt
MattGillman wrote:
nitt wrote:On new operating systems, usually "timeout /nobreak 5 > nul" will pause the Batch file. But on older systems you may need to use "ping 0 -n 5 > nul". The both will pause or 5 intervals.


but pausing the process isnt going to close the window though, is it?

Sorry, what question are you replying to?


The one about closing the window after a timelimit.

Just create a secondary Batch file that will close CMD.EXE after a certain amount of time, then call on it at the start of the primary Batch file.

In case you don't know, that would be "taskkill /f /im cmd.exe > nul".

Opening after time will be the same, but with "start {batname}.bat".

Re: Time limit on CMD window to close

Posted: 05 May 2011 01:19
by MattGillman
Ok so where do i put in where do i put in the time on this new BAT?

Re: Time limit on CMD window to close

Posted: 05 May 2011 11:09
by aGerman
Pass the time and the window title as arguments.

kill.bat

Code: Select all

@echo off &setlocal
set /a num=%~1 + 1
ping -n %num% localhost >nul
taskkill /F /IM cmd.exe /FI "WINDOWTITLE eq %~2"


Now you could use it like that (for your 1st batch to close the 2nd one):

Code: Select all

:: ... ::
start "" "c:\Users\Matthew\Desktop\-\Matrix.BAT"
start "" /min "kill.bat" 10 "System Decryption"
:: ... ::

As you can see you can run it in a minimized window. The first argument is the number of seconds and the second argument is the window title of the batch you want to quit.

Regards
aGerman

(BTW: my codes are not tested)