title: Batch file does action after it's closed
body: <p>I want to create a batch file, that detects when the CMD window gets closed and does directly after an action.</p>
  
  <p>If for example the the textfile text.txt is opened, and after i launch the batch file called prog.bat with this code inside:</p>
  
  <pre><code>@echo off
  
  echo Hello
  
  pause
  </code></pre>
  
  <p>How can i tell the batch that if the CMD window which is currently opend, should taskill text.txt file when somebody closes the CMD window?(by closing with ending process or hitting the X on the top)</p>