title: Restore a minimised application via VBS within an HTA
body: <p>I have an HTA that is minimised while it carries out a backup.  After this backup is complete I'd like to restore the HTA, but I'm having trouble.</p>
  
  <p>I've tried a few things (below), but with no success.  Is anyone able to point me towards a definitive solution?</p>
  
  <p>First I tried to simply activate the HTA, but this failed.  I'm no expert, but my understanding is that doing this should mimick a mouse click on the HTA in the task bar, thus restoring it -</p>
  
  <pre><code>Sub RestoreBackupHTA()
  
      Shell.AppActivate "Backup"
  
  End Sub
  </code></pre>
  
  <p>Next I tried to activate the HTA and then send the keys to "restore" the active window, but that also failed -</p>
  
  <pre><code>Sub RestoreBackupHTA()
  
      Shell.AppActivate "Backup"
      Shell.SendKeys "% r"
  
  End Sub
  </code></pre>
  
  <p>Finally I tried to first activate the HTA and then send the keys to "restore" the active window after a short timeout (I found a couple of posts suggesting this could help to ensure that the HTA was fully active before sending the keys to restore it), but again, failure -</p>
  
  <pre><code>Sub RestoreBackupHTA()
  
      Shell.AppActivate "Backup"
      Call window.setTimeout("RestoreBackupHTAAfterWait", 500, "VBScript")
  
  End Sub
  
  Sub RestoreBackupHTAAfterWait()
  
      '** Create a tempory Shell object (required as the global Shell object is out of scope for some reason *'
      Dim tmpShell
      Set tmpShell = CreateObject("Wscript.Shell")
  
      tmpShell.SendKeys "% r" ' Restore the HTA
  
      Set tmpShell = Nothing  ' Destroy the tmpShell object
  
  End Sub
  </code></pre>
  
  <p><strong>Notes</strong> -</p>
  
  <ol>
  <li>The HTA has the ID "Backup" (<code>&lt;HTA:APPLICATION ID="Backup" ... /&gt;, and so "Backup" is displayed in the title bar when it is running (and as the title in the task manager).  This is why I'm using it as the</code>title<code>parameter for</code>Shell.AppActivate`, and according to <a href="https://msdn.microsoft.com/en-us/library/wzcddbek%28v=vs.84%29.aspx" rel="nofollow">this MSDN page</a> that should be correct.</li>
  <li><code>Shell</code> is declared and set globally, thus it is available to the <code>RestoreBackupHTA</code> procedure in the examples above.</li>
  </ol>