title: How to launch HTA from VBScript
body: <p>HTA calls external VBScript and after that it turns into suspend mode. At this point control is transferred to the VBScript. As a result of VBScript code execution it may happen that the machine would be rebooted. After the reboot HTA starts automatically and stays suspended; while the VBScript continues to work (let's assume they both start from Startup). Upon completion of VBScrip work I'd like control to be transferred back to the HTA and a HTA subroutine to be executed. Let's say this subroutine is Window_OnLoad. How can I do this? Is there an instruction to open HTA and after that execute a sub? If I launch to HTA from VBScript with Run method (or ShellExecute) I get only HTA window (you remember that HTA is still suspended) but my goal is to wake up HTA and make it running.</p>
  
  <h1>Some additional details</h1>
  
  <p>I didn't want to publish the code here as this is general question and the code might give more confusion... Primary task of this HTML Application is giving administrator of workgroup/domain a very smooth way for customization of just installed Windows 7 (change computer name, join to domain, set local computer description, set domain computer description, regional settings, etc.). HTA offers also opportunity to choose what steps to be done - this is realized as a list of checkboxes; so that administrator can change computer name but do not include computer into the domain and set up power settings for instance. Some steps requires computer reboot; but some steps are okay to pass control to the next step without reboot. Here is a general idea: I have HTA that allows user to enter some data; also there is XML file. XML is used to keep not only user data but also some instructions for steps to be done; e.g. for user data XML contains</p>
  
  <pre><code>&lt;computername/&gt;
  &lt;PCdescription/&gt;
  &lt;DomainName/&gt;
  &lt;OUName/&gt;
  </code></pre>
  
  <p>whilst the step is described in this manner:</p>
  
  <pre><code>&lt;step&gt;
      &lt;description&gt;Include PC into Domain&lt;description/&gt;
      &lt;filetorun&gt;/scripts/domain.vbs&lt;/filetorun&gt;
      &lt;arguments&gt;&lt;/arguments&gt;
      &lt;completion&gt;reboot&lt;/completion&gt;
  &lt;/step&gt;
  </code></pre>
  
  <p>Here <code>description</code> is the step name which is shown in HTA window, <code>filetorun</code> gives the VBScript (or batch file) to be executed to complete the step, <code>arguments</code> are compiled from the user data and saved to XML, and <code>complete</code> shows whether reboot is required after the step is completed.</p>
  
  <p>VBScript is executed by these instructions:</p>
  
  <pre><code>strFile = oNode.SelectSingleNode("filetorun").Text
  strArgs = oNode.SelectSingleNode("arguments").Text
  stringtorun = strFile &amp; " " &amp; strArgs
  result = Createobject("WScript.Shell").Run(stringtorun,,true)
  </code></pre>
  
  <p>where oNode is XML node for the current step.
  All instructions are nested to the HTA like this</p>
  
  <pre><code>    &lt;html&gt;
          &lt;head&gt;
              '...........
              &lt;HTA:APPLICATION
              APPLICATIONNAME="MyHTMLapplication"
              VERSION="1.0"/&gt;
              '...............
          &lt;/head&gt;
          &lt;script language="VBScript"&gt;
              Sub Window_OnLoad
                  '......................
                  ' Populate form, save XML, other operations
                  '......................
                  '--------------execute step command---------------
                  strFile = oNode.SelectSingleNode("filetorun").Text
                  strArgs = oNode.SelectSingleNode("arguments").Text
                  stringtorun = strFile &amp; " " &amp; strArgs
                  result = oShell.Run(stringtorun,,true)
                  '-------------------------------------------------
                  If Reboot_is_not_required Then
                      'computer restart not required, proceeding with the next step...
                      Window_OnLoad
                  End If
              End Sub
          &lt;/script&gt;
          &lt;body&gt;
              ........................
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>Up to the present day completion was allowed to take two values: <em>Reboot</em> and <em>NoReboot</em>. The latter parameter causes recurrent call of <strong>Window_OnLoad</strong> when current step is completed and we are about to make next step.
  Now there is a need to introduce parameter <em>Delay</em>. I'm going to use this parameter for such external scripts that require system reboot without passing control back to HTA.</p>
  
  <p>HTA starts automatically after system reboot. So, if the current step is marked as <em>Delay</em> then HTA will only populate the forms. I want that external script which executes the current step in such model, would somehow pass control back to HTA. But this is not enough because at this stage HTA work is suspended. To wake HTA up and force to perform next step I need to call a subroutine. How to do this from VBScript?</p>
  
  <p>Do not be too hard on me. This is my first steps in programming.
  Thank you in advance.</p>