On Exit Do Command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

On Exit Do Command

#1 Post by BAT Beginner » 07 Feb 2010 20:32

Is there any code that does a command when the executor closes the .bat file with the red X?If so, PLEASE post it below!

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: On Exit Do Command

#2 Post by aGerman » 08 Feb 2010 05:24

BAT Beginner

There is no command for such intention.
Batches are interpreted line by line. If you close the window this interpretation is interrupted and nothing else will go on.

Regards
aGerman

BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

Re: On Exit Do Command

#3 Post by BAT Beginner » 08 Feb 2010 16:39

Can you disable the red X at least?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: On Exit Do Command

#4 Post by aGerman » 08 Feb 2010 16:49

No, you can't.
Also you can't disable Ctrl+C.

Why do you need it?

Regards
aGerman

BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

Re: On Exit Do Command

#5 Post by BAT Beginner » 08 Feb 2010 17:59

Because, as my name states, i am a .bat beginner and i want to know all the code i can possibly learn so i can become an expert.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: On Exit Do Command

#6 Post by aGerman » 09 Feb 2010 04:07

My question was geared if you would need it for something special.

Batch is a very primordial class. It is based on good old DOS and has a lot of limitations.
Batch doesn't have any event handler. That means you can't figure out
- which key is pressed
- which mouse button is pushd
- where the mause cursor is placed
and many more...
Also you can't use any WinAPI function.

Note that batch is no programming language. Nearly each command is a separate *.exe or *.com file.

Regards
aGerman

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: On Exit Do Command

#7 Post by avery_larry » 10 Feb 2010 11:24

aGerman wrote:No, you can't.
Also you can't disable Ctrl+C.

Why do you need it?

Regards
aGerman

Actually, start /wait /b will disable Ctrl+C for the duration of that particular command.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: On Exit Do Command

#8 Post by aGerman » 10 Feb 2010 15:21

avery_larry wrote:Actually, start /wait /b will disable Ctrl+C for the duration of that particular command.

You are right, but that doesn't change the fact that you can't disable it for the whole run time of a batch code.

regards
aGerman

Stergioss
Posts: 5
Joined: 12 Feb 2010 10:33

Re: On Exit Do Command

#9 Post by Stergioss » 12 Feb 2010 10:59

Well you can disable the RED X button but only with Visual Basic
At least this is my opinion . . .

aGerman wrote:- which key is pressed


Major wrong!

Code: Select all

@ECHO OFF
TITLE Keyboard Simulator
MODE CON cols=41 lines=5
:a
SET q1=
SET q2=
SET w1=
SET w2=
SET e1=
SET e2=
SET r1=
SET r2=
SET t1=
SET t2=
SET y1=
SET y2=
SET u1=
SET u2=
SET i1=
SET i2=
SET o1=
SET o2=
SET p1=
SET p2=
SET a1=
SET a2=
SET s1=
SET s2=
SET d1=
SET d2=
SET f1=
SET f2=
SET g1=
SET g2=
SET h1=
SET h2=
SET j1=
SET j2=
SET k1=
SET k2=
SET l1=
SET l2=
SET z1=
SET z2=
SET x1=
SET x2=
SET c1=
SET c2=
SET v1=
SET v2=
SET b1=
SET b2=
SET n1=
SET n2=
SET m1=
SET m2=
SET x11x=
SET x12x=
SET x21x=
SET x22x=
SET x31x=
SET x32x=
SET x41x=
SET x42x=
SET x51x=
SET x52x=
SET x61x=
SET x62x=
SET x71x=
SET x72x=
SET x81x=
SET x82x=
SET x91x=
SET x92x=
SET x01x=
SET x02x=
IF %ERRORLEVEL%==1 (
SET q1=[
SET q2=]
)
IF %ERRORLEVEL%==2 (
SET w1=[
SET w2=]
)
IF %ERRORLEVEL%==3 (
SET e1=[
SET e2=]
)
IF %ERRORLEVEL%==4 (
SET r1=[
SET r2=]
)
IF %ERRORLEVEL%==5 (
SET t1=[
SET t2=]
)
IF %ERRORLEVEL%==6 (
SET y1=[
SET y2=]
)
IF %ERRORLEVEL%==7 (
SET u1=[
SET u2=]
)
IF %ERRORLEVEL%==8 (
SET i1=[
SET i2=]
)
IF %ERRORLEVEL%==9 (
SET o1=[
SET o2=]
)
IF %ERRORLEVEL%==10 (
SET p1=[
SET p2=]
)
IF %ERRORLEVEL%==11 (
SET a1=[
SET a2=]
)
IF %ERRORLEVEL%==12 (
SET s1=[
SET s2=]
)
IF %ERRORLEVEL%==13 (
SET d1=[
SET d2=]
)
IF %ERRORLEVEL%==14 (
SET f1=[
SET f2=]
)
IF %ERRORLEVEL%==15 (
SET g1=[
SET g2=]
)
IF %ERRORLEVEL%==16 (
SET h1=[
SET h2=]
)
IF %ERRORLEVEL%==17 (
SET j1=[
SET j2=]
)
IF %ERRORLEVEL%==18 (
SET k1=[
SET k2=]
)
IF %ERRORLEVEL%==19 (
SET l1=[
SET l2=]
)
IF %ERRORLEVEL%==20 (
SET z1=[
SET z2=]
)
IF %ERRORLEVEL%==21 (
SET x1=[
SET x2=]
)
IF %ERRORLEVEL%==22 (
SET c1=[
SET c2=]
)
IF %ERRORLEVEL%==23 (
SET v1=[
SET v2=]
)
IF %ERRORLEVEL%==24 (
SET b1=[
SET b2=]
)
IF %ERRORLEVEL%==25 (
SET n1=[
SET n2=]
)
IF %ERRORLEVEL%==26 (
SET m1=[
SET m2=]
)
IF %ERRORLEVEL%==27 (
SET x11x=[
SET x12x=]
)
IF %ERRORLEVEL%==28 (
SET x21x=[
SET x22x=]
)
IF %ERRORLEVEL%==29 (
SET x31x=[
SET x32x=]
)
IF %ERRORLEVEL%==30 (
SET x41x=[
SET x42x=]
)
IF %ERRORLEVEL%==31 (
SET x51x=[
SET x52x=]
)
IF %ERRORLEVEL%==32 (
SET x61x=[
SET x62x=]
)
IF %ERRORLEVEL%==33 (
SET x71x=[
SET x72x=]
)
IF %ERRORLEVEL%==34 (
SET x81x=[
SET x82x=]
)
IF %ERRORLEVEL%==35 (
SET x91x=[
SET x92x=]
)
IF %ERRORLEVEL%==36 (
SET x01x=[
SET x02x=]
)
CLS
ECHO.%x11x%1%x12x% %x21x%2%x22x% %x31x%3%x32x% %x41x%4%4%x42x% %x51x%5%x52x% %x61x%6%x62x% %x71x%7%x72x% %x81x%8%x82x% %x91x%9%x92x% %x01x%0%x02x%
ECHO. %q1%Q%q2% %w1%W%w2% %e1%E%e2% %r1%R%r2% %t1%T%t2% %y1%Y%y2% %u1%U%u2% %i1%I%i2% %o1%O%o2% %p1%P%p2%
ECHO.  %a1%A%a2% %s1%S%s2% %d1%D%d2% %f1%F%f2% %g1%G%g2% %h1%H%h2% %j1%J%j2% %k1%K%k2% %l1%L%l2%
ECHO.   %z1%Z%z2% %x1%X%x2% %c1%C%c2% %v1%V%v2% %b1%B%b2% %n1%N%n2% %m1%M%m2%
CHOICE /C qwertyuiopasdfghjklzxcvbnm1234567890 /N > nul
GOTO a


Just found you teacher!
Just joined :wink: 8)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: On Exit Do Command

#10 Post by aGerman » 12 Feb 2010 13:14

Stergioss
you're a joker :lol:
Okay, I've got it to work:

Code: Select all

@echo off
TITLE Keyboard Simulator
MODE CON cols=41 lines=6
set ERRL=0
:a
SET q1=
SET q2=
SET w1=
SET w2=
SET e1=
SET e2=
SET r1=
SET r2=
SET t1=
SET t2=
SET y1=
SET y2=
SET u1=
SET u2=
SET i1=
SET i2=
SET o1=
SET o2=
SET p1=
SET p2=
SET a1=
SET a2=
SET s1=
SET s2=
SET d1=
SET d2=
SET f1=
SET f2=
SET g1=
SET g2=
SET h1=
SET h2=
SET j1=
SET j2=
SET k1=
SET k2=
SET l1=
SET l2=
SET z1=
SET z2=
SET x1=
SET x2=
SET c1=
SET c2=
SET v1=
SET v2=
SET b1=
SET b2=
SET n1=
SET n2=
SET m1=
SET m2=
SET x11x=
SET x12x=
SET x21x=
SET x22x=
SET x31x=
SET x32x=
SET x41x=
SET x42x=
SET x51x=
SET x52x=
SET x61x=
SET x62x=
SET x71x=
SET x72x=
SET x81x=
SET x82x=
SET x91x=
SET x92x=
SET x01x=
SET x02x=
IF %ERRL%==1 (
SET q1=[
SET q2=]
)
IF %ERRL%==2 (
SET w1=[
SET w2=]
)
IF %ERRL%==3 (
SET e1=[
SET e2=]
)
IF %ERRL%==4 (
SET r1=[
SET r2=]
)
IF %ERRL%==5 (
SET t1=[
SET t2=]
)
IF %ERRL%==6 (
SET y1=[
SET y2=]
)
IF %ERRL%==7 (
SET u1=[
SET u2=]
)
IF %ERRL%==8 (
SET i1=[
SET i2=]
)
IF %ERRL%==9 (
SET o1=[
SET o2=]
)
IF %ERRL%==10 (
SET p1=[
SET p2=]
)
IF %ERRL%==11 (
SET a1=[
SET a2=]
)
IF %ERRL%==12 (
SET s1=[
SET s2=]
)
IF %ERRL%==13 (
SET d1=[
SET d2=]
)
IF %ERRL%==14 (
SET f1=[
SET f2=]
)
IF %ERRL%==15 (
SET g1=[
SET g2=]
)
IF %ERRL%==16 (
SET h1=[
SET h2=]
)
IF %ERRL%==17 (
SET j1=[
SET j2=]
)
IF %ERRL%==18 (
SET k1=[
SET k2=]
)
IF %ERRL%==19 (
SET l1=[
SET l2=]
)
IF %ERRL%==20 (
SET z1=[
SET z2=]
)
IF %ERRL%==21 (
SET x1=[
SET x2=]
)
IF %ERRL%==22 (
SET c1=[
SET c2=]
)
IF %ERRL%==23 (
SET v1=[
SET v2=]
)
IF %ERRL%==24 (
SET b1=[
SET b2=]
)
IF %ERRL%==25 (
SET n1=[
SET n2=]
)
IF %ERRL%==26 (
SET m1=[
SET m2=]
)
IF %ERRL%==27 (
SET x11x=[
SET x12x=]
)
IF %ERRL%==28 (
SET x21x=[
SET x22x=]
)
IF %ERRL%==29 (
SET x31x=[
SET x32x=]
)
IF %ERRL%==30 (
SET x41x=[
SET x42x=]
)
IF %ERRL%==31 (
SET x51x=[
SET x52x=]
)
IF %ERRL%==32 (
SET x61x=[
SET x62x=]
)
IF %ERRL%==33 (
SET x71x=[
SET x72x=]
)
IF %ERRL%==34 (
SET x81x=[
SET x82x=]
)
IF %ERRL%==35 (
SET x91x=[
SET x92x=]
)
IF %ERRL%==36 (
SET x01x=[
SET x02x=]
)
CLS
ECHO.%x11x%1%x12x% %x21x%2%x22x% %x31x%3%x32x% %x41x%4%4%x42x% %x51x%5%x52x% %x61x%6%x62x% %x71x%7%x72x% %x81x%8%x82x% %x91x%9%x92x% %x01x%0%x02x%
ECHO. %q1%Q%q2% %w1%W%w2% %e1%E%e2% %r1%R%r2% %t1%T%t2% %y1%Y%y2% %u1%U%u2% %i1%I%i2% %o1%O%o2% %p1%P%p2%
ECHO.  %a1%A%a2% %s1%S%s2% %d1%D%d2% %f1%F%f2% %g1%G%g2% %h1%H%h2% %j1%J%j2% %k1%K%k2% %l1%L%l2%
ECHO.   %z1%Z%z2% %x1%X%x2% %c1%C%c2% %v1%V%v2% %b1%B%b2% %n1%N%n2% %m1%M%m2%
CHOICE /C:qwertyuiopasdfghjklzxcvbnm1234567890 /N > nul
set ERRL=%errorlevel%
GOTO a


But:
Stergioss wrote:Major wrong!

Hmm, try to detect F1 - F12, Print, Insert, Del, Shift, Ctrl, Alt, Arrows ... :wink:
And try if another window is focussed ...

Regards
aGerman

BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

Re: On Exit Do Command

#11 Post by BAT Beginner » 12 Feb 2010 15:11

Ok All those codes are Awesome
But i was wondering, how to you make sounds like you did with the keyboard batch?
I would really love that kind of code.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: On Exit Do Command

#12 Post by aGerman » 12 Feb 2010 16:26

BAT Beginner wrote:But i was wondering, how to you make sounds like you did with the keyboard batch?

I'm wondering why you can hear a sound :?:

BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

Re: On Exit Do Command

#13 Post by BAT Beginner » 12 Feb 2010 17:18

When You Press ENTER it makes a noise.Also ; or , or ] etc...

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: On Exit Do Command

#14 Post by aGerman » 12 Feb 2010 17:40

This beep is a warning of the choice command. Because only the keys behind the /C: switch are allowed.

But you are able to generate a beep using the echo command with ASCII character 07.
copy/paste:

Code: Select all

@echo off
:beep
cls
echo 
ping -n 2 localhost>nul
goto beep


Regards
aGerman

Stergioss
Posts: 5
Joined: 12 Feb 2010 10:33

Re: On Exit Do Command

#15 Post by Stergioss » 12 Feb 2010 18:58

aGerman wrote:Hmm, try to detect F1 - F12, Print, Insert, Del, Shift, Ctrl, Alt, Arrows ... :wink:
And try if another window is focussed ...

Well ok But still with some more research . . .!

BAT Beginner wrote:Ok All those codes are Awesome
But i was wondering, how to you make sounds like you did with the keyboard batch?
I would really love that kind of code.

Just add the Echo Icon

aGerman wrote:IF %ERRL%==1 (
SET q1=[
SET q2=]
Echo Beep Icon Here(Too lazy to Copy paste! :D
)



Also aGerman :
1)Bist du auf deutchland?
2)Come to a good forum i am visiting
http://www.lingubender.com/forum/index.php
There is a guy With more knownlodge!
I would really like to see u 2 discussing!
My name there is also Stergioss

Post Reply