1

So I wrote a tool with some batch commands, nothing specific. In the beginning the user can choose which task to perform thanks to a loop.

In that loop I included the "Q" option, as to quit the batch file. When this happens, it gets written to a logfile to check when the user started the script(s), and when it ended.

The issue is this only happens if the user actually quits/exits with Q. If (s)he quits by just closing the batch file, this won't be logged.

In short: how can I record when the user has quit the batch file without using the build-in function?

2
  • Unless some other process/batch file is monitoring it, you can't log the time it is terminated by a user clicking the close icon. Commented Nov 13, 2013 at 13:55
  • 1
    On second thought - You could have your batch file update the timestamp on a temp file regularly and the file will retain the date and time of the last time it was updated. It would then normally require manual intervention to get the time/date - but that would give you an approximate time of when the batch file was closed. Commented Nov 13, 2013 at 15:15

1 Answer 1

1

a batch file can't receive the "exiting"-event. What you can do is:

  1. Make a launcher.bat file, that starts the original (yourfilename).bat file with:

    start /wait (yourfilename).bat

  2. the launcher.bat file will now wait until you close the second (yourfilename).bat file. place your log-information on the next line of launcher.bat

  3. convert launcher.bat to launcher.exe using bat to exe converter (and make it invisible).

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, I know about that technique but wanted to avoid it. Thanks though!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.