title: VBScript hangs when launching batch file with WShell.Script Run
body: <p>During an install of PostgreSQL 9.1.2 on my Windows 7 64-bit Home Premium box, the installation hung. After a long furious search I discovered the problem was that an installer VB Script was hung waiting for a batch file to complete in a hidden window. </p>
  
  <p>I isolated the problem to the following line of code:</p>
  
  <pre><code>Dim objShell
  Set objShell = WScript.CreateObject("WScript.Shell")
  objShell.Run "hello.bat", 1, True
  </code></pre>
  
  <p>(where <code>1</code> sets WindowStyle to Visible and <code>True</code> waits for completion). The <code>Run</code> call had launched the command prompt but was not executing the batch file. Thus, it would never complete. </p>
  
  <p>I solved the problem by launching cmd.exe instead of the batch file directly, according to numerous online sources:</p>
  
  <pre><code>objShell.Run "%COMSPEC% /c hello.bat", 1, True
  </code></pre>
  
  <p>Since the fix is buried in the PostgreSQL installer (and I've submitted a <a href="http://postgresql.1045698.n5.nabble.com/Windows-x86-64-One-Click-Install-9-1-2-1-9-0-6-1-hangs-on-quot-initialising-the-database-cluster-quo-td5431837.html" rel="nofollow">bug report</a>), I can only <a href="http://forums.enterprisedb.com/posts/list/2870.page#11379" rel="nofollow">work around</a> the problem unless the installer is modified.</p>
  
  <p>But my main questions are:</p>
  
  <ol>
  <li>Why does the first call hang? </li>
  <li>Why use %COMSPEC% instead of calling the batch directly?</li>
  </ol>
  
  <p>In regards to #2, could this be because executing a .bat directly makes an assumption that the default action associated with a .bat file is to execute it? I've in the past (on other machines) changed this default action to 'Edit'. And if I'd done that, I would have hung the PostgreSQL installer as well! (I imagine)</p>
  
  <p>The batch file executes normally on other machines. So there is something weird on this one laptop. So in regards to #1, I need to figure out why this one laptop is different. I should note that there are some weird behaviors with batch files on this machine (one which I just noticed):</p>
  
  <ol>
  <li>The context menu actions contain only "Open" and are missing "Edit", "Run", "Run As"</li>
  <li>Double-clicking a batch file opens a command prompt but does not execute the batch file</li>
  </ol>
  
  <p>I <em>just</em> noticed #2 while writing this. Clearly the default action for .bat is messed up. Yesterday I nearly bricked my computer removing Context Menu Handlers from my registry as recommended by several sites trying to restore my "Edit", "Run", etc. entries.</p>
  
  <p>Any advice on questions 1 and 2 would be appreciated. </p>
  
  <p>Thanks,
  Eric</p>