title: how do I kill all cmd.exe except the one currently running from batch?
body: <p>The past few days I have been working on a script that I thought would be rather easy but it seems not, and I do understand why. My problem is how to get around it. </p>
  
  <p><strong>The batch script I need explained:</strong></p>
  
  <p>I have a script that runs in cmd.exe that does a bunch of things like moving a huge amount of files from a location to another. Lets call it 
  <code>movefile.cmd</code>. This script works, but happens to stop sometimes (very rarely - lets not go into why and that script). Its important that this script always runs, so my idea here was to create a batch that exits cmd.exe and then re-opens the script each hour or so. Lets call this script <code>restartcmd.bat</code> </p>
  
  <p><em>Sounds perfectly easy as I could do this:</em></p>
  
  <pre><code>@echo off
  
  :loop
  
  start c:\script\movefile.cmd 
  
  Timeout /nobreak /t 3600
  
  Taskkill cmd.exe
  
  goto loop
  </code></pre>
  
  <p>But obviously this doesn't work because my new script also runs in cmd.exe, so it would kill this process as well. </p>
  
  <p><strong>What I've tried:</strong></p>
  
  <p>So I made a copy of cmd.exe and renamed it into dontkillthis.exe. I run dontkillthis.exe and then open the restardcmd.bat from dontkillthis.exe - this works perfectly! But I need to be able to just dobbleclick my script instead of doing that. Why? Because its supposed to be as easy as possible and I want my restartcmd.bat to be in my startup folder.</p>
  
  <p>I've been looking at the ideas of getting the exact process ID of cmd.exe and shutting that so that my dontkillthis.exe will remain, but I can't seem to nail it. Tried all thats written in here <a href="https://stackoverflow.com/questions/12024149/how-to-kill-all-batch-files-except-the-one-currently-running">how to kill all batch files except the one currently running</a> , but I can't get it to work. </p>
  
  <p>I'm not sure if I'm being confused or if it actually is a bit hard to do this. </p>
  
  <p>I'd really appreciate some help here.</p>
  
  <p>Best Regards</p>
  
  <p>MO</p>