title: Restarting explorer.exe only opens an explorer window
body: <p><strong>The Problem</strong></p>
  
  <p>In one part of a batch file (kind of, see Extra Information) I need to restart
  Explorer, so I use the, tried-and-tested method of</p>
  
  <pre><code>taskkill /f /im explorer.exe &gt;nul
  explorer.exe
  </code></pre>
  
  <p>Then this happens</p>
  
  <ol>
  <li><code>explorer.exe</code> is successfully terminated</li>
  <li><code>explorer.exe</code> is started (see Image 2), but only an
  Explorer window opens, which I am left with indefinitely (see Image 1)</li>
  </ol>
  
  <p>I can then only properly restart Explorer by starting a new task from Task
  Manager, as, I'm assuming, <code>Win + R</code> is part of Explorer.</p>
  
  <p><strong>Extra Information</strong></p>
  
  <p>Now, I say "kind of" as I'm running the batch file from a self-executing SFX
  archive, created with WinRAR. So, when executed, the contents of the archive are
  extracted to <code>%temp%</code> and a user-defined file (usually a boot-strapper and, in
  this case, my batch file) is run upon successful extraction.</p>
  
  <p>So far, I've deduced</p>
  
  <ol>
  <li><code>explorer.exe</code> definitely is being fully killed.</li>
  <li>The batch file definitely is called and executed correctly, as it runs and
  everything else in the script works as designed, except for the line that
  starts <code>explorer.exe</code></li>
  <li>The command to restart Explorer isn't "badly timed", or anything, as I've
  tried delaying it.</li>
  <li>The batch file works perfectly when manually extracted from the archive, so
  it's not a problem with the compression or extraction processes.</li>
  <li>Even with commands like <code>start explorer.exe | cmd.exe</code> Explorer doesn't
  restart properly, so it's definitely not a problem with the <code>.bat</code> file.</li>
  </ol>
  
  <p>I can confirm that it works on Windows XP and Windows 7 x86 but not Windows 7
  x64 (which is my system).</p>
  
  <p><strong>Status</strong></p>
  
  <p>At the moment, I'm suspicious of WinRAR, as I've proved that the code itself
  works. So, I'm creating the self-executing SFX with different versions of
  WinRAR. So far, I've tried versions:</p>
  
  <ul>
  <li>4.11 x86</li>
  <li>4.11 x64</li>
  <li>4.20b3 x86</li>
  <li>4.20b3 x64</li>
  </ul>
  
  <p>and had the same results every time.</p>
  
  <p>I submitted a bug report to dev@rarlab.com yesterday and <strong>got a reply from
  Eugene Roshal himself</strong> this morning</p>
  
  <blockquote>
    <p>Hello,
    SFX module uses ShellExecuteEx to start a setup application.
    Normally it works well. I do not know why Explorer decides to switch
    to windowed mode.
    Now I built a small standalone program</p>
  </blockquote>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;windows.h&gt;    
  void main()
  {
    SHELLEXECUTEINFO si;
    memset(&amp;si,0,sizeof(si));
    si.cbSize=sizeof(si);
    si.lpFile="test.bat";
    si.nShow=SW_SHOWNORMAL;
    ShellExecuteEx(&amp;si);
  }
  </code></pre>
  
  <blockquote>
    <p>which runs test.bat with contents as in your sample. This program
    shows exactly the same behavior as WinRAR SFX, so Explorer is started
    in window.</p>
  </blockquote>
  
  <p>and a second email this morning</p>
  
  <blockquote>
    <p>Sorry, no advice now. I replaced ShellExecuteEx with CreateProcess</p>
  </blockquote>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;windows.h&gt;
  void main()
  {
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    memset(&amp;si,0,sizeof(si));
    si.cb=sizeof(si);
    CreateProcess(NULL,"test.bat",NULL,NULL,TRUE,0,NULL,NULL,&amp;si,&amp;pi);
  }
  </code></pre>
  
  <blockquote>
    <p>but result is the same. I tried to use other SW_ flags like
    SW_SHOWDEFAULT or SW_RESTORE with ShellExecuteEx also as "open"
    and "explore" lpVerb, but it does not help. For now I do not
    understand the logic behind this windowed versus desktop mode.</p>
  </blockquote>
  
  <p>I realise the outlook is grim but, I hope that's of help to someone..</p>
  
  <p><strong>Proof / Evidence</strong></p>
  
  <p>Link to an SFX archive demonstrating this, if anyone wants it:
  <a href="https://dl.dropbox.com/u/27573003/Social%20Distribution/restart-explorer.exe" rel="noreferrer">https://dl.dropbox.com/u/27573003/Social%20Distribution/restart-explorer.exe</a></p>
  
  <p><img src="https://i.stack.imgur.com/ART4Z.png" alt="image 1"></p>
  
  <p><img src="https://i.stack.imgur.com/HE41j.jpg" alt="image 2"></p>
  
  <p>You may notice here that I'm running the commands inside a VM (as denoted by
  <code>VMwareTray.exe</code>) but it is not a VM-caused conflict. I've tested the exact same
  files on my own host system (which is the same OS) and have had the same
  results.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I'm experiencing similar "works outside of an SFX archive but not from one"
  problems when using <code>REG&nbsp;ADD</code> in a completely different project.
  I just don't think SFX archives play nice with batch files.</p>