1.

Solve : Can I execute commands when the window closes??

Answer»

I have been programming a chatroom for me and my friends on BATCH.
I was wondering if I could execute a command as the WINDOW is closing.
What this would be used for is to display:
CODE: [Select]echo // %username% has left.when they X out.
Is this possible?You can have an exit script that it can run in the background, but this would have to remain open while the chat service is running
Code: [Select]@echo off
:loop
tasklist | find "CHAT.exe"
if %errorlevel% == 0 goto loop
REM send echo // %username% has left. command
exit /b

*untestedQuote from: Lemonilla on June 19, 2013, 10:17:34 AM

You can have an exit script that it can run in the background, but this would have to remain open while the chat service is running
Code: [Select]@echo off
:loop
tasklist | find "CHAT.exe"
if %errorlevel% == 0 goto loop
REM send echo // %username% has left. command
exit /b

*untested

I'm sorry, I don't understand what you mean. I don't know how to run it in the background. The batch itself is called Chatroom.bat and the LOG is called ChatLog.txt, if this helps at all.If you were to MAKE chatroom.bat into a .exe program, then you would use
Code: [Select]@echo off
:loop
tasklist | find "CHAT.exe"
if %errorlevel% == 0 goto loop
echo ^/^/ %username% has left. >>ChatLog.txt
REM this is where you resend your chatlog.
exit /b

Otherwise, you would have to make a logout option/command within the chat system.
Code: [Select]REM say we are using %input% as our veriable that would get entered into chatlog.txt
if "%input%"=="$logout" (
echo ^/^/ %username% has left. >>ChatLog.txt
REM this is where you resend your chatlog.
)

this would not happen if they were to just x out of the program.


Discussion

No Comment Found