Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA to feed VBS Variable

Status
Not open for further replies.

cwsstins

MIS
Aug 10, 2004
412
US
I have a vbs file that runs a .hta with two radio buttons. My objective is to capture the selection made in the .hta and bring it back to the vbs to use it as a variable for a drive mapping.

The vbs has
Code:
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.MapNetworkDrive "Z:", "\\" & GSServer & "\goldapp$",True

The GSServer should equal whatever is selected in the .hta.
Here's the .hta:
Code:
<SCRIPT LANGUAGE="VBScript">

Sub RunScript

    If ComputerOption(0).Checked Then
        strComputer = ComputerOption(0).Value
    End If
    If ComputerOption(1).Checked Then
        strComputer = ComputerOption(1).Value
    End If
    If strComputer = "" Then
        Exit Sub
    End If

End Sub

Sub CancelScript
   Self.Close()
End Sub

</SCRIPT>

<BODY>
<input type="radio" name="ComputerOption" value="GOLD">GOLD<BR>
<input type="radio" name="ComputerOption" value="GSPROD">GSPROD<P>

<input id=runbutton class="button" type="button" value="Run Script" name="ok_button" 
onClick="RunScript">
&nbsp;&nbsp;&nbsp;
<input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" 
onClick="CancelScript">

</BODY>

So how do I get the radio button selected and bring it back into the vbs file that runs the .hta?
 
Why not having all the code in the HTA ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
There is a lot more going on here that I haven't described. I've got a manual process that involves uninstalling an application, deleting associated directories/files, then re-installing the application, mapping a drive, and making several other changes.

But most of the changes require no intervention from the user, they are being done in silent mode. The only time I need a user interface is for selecting a server name (from two possibilities) to map the drive.
 
Have the hta collecting all the necessary parameters and then do the job(s).

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OK, I tried that and I'm getting an error message indicating Object required: 'wscript'

For this line:
Set WSHShell = wscript.createObject("wscript.shell")
 
And what about this ?
Set WSHShell = CreateObject("WScript.Shell")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Looks better...but I've got a couple Wscript.sleep commands in there as well. They are bombing out...is there another hta-friendly format for waiting or sleeping to let one process finish before starting the next?
 
let one process finish before starting the next
How are the process started ?
Have a look at the 3rd argument of the Run method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Try to load an external vbscript to let it run the sleep.
I don't think Wscript.exe is reachable from HTA

Code:
<SCRIPT LANGUAGE="VBSCRIPT" SRC="Sleep.vbs">
</SCRIPT>
 
There are ways, but you have to write your HTA more like a VB program using forms rather than a sequential script. In other words you need to use events and timers, and poll for completion.

Here's a simple example:

HTAVBS.vbs
Code:
With WScript
  .Sleep 10000
  .Quit 47 'Return result to HTA.
End With

HTAVBS.hta
Code:
<HTML>
<HEAD>
  <TITLE>
    HTAVBS: Start a WSH Script, Wait For Completion
  </TITLE>
  <HTA:application scroll=no>
  <STYLE>
    div.clsIndent {margin-left: 30px}
    div.clsIndentRed {margin-left: 30px; color: red}
  </STYLE>
  <SCRIPT language=VBScript>
    Option Explicit
    Const WshRunning = 0
    Const WshFinished = 1
    Dim wshShell
    Dim wseExternal
    Dim tmrExternal

    Sub cmdStart_onclick()
      On Error Resume Next
	  Set wseExternal = _
	    wshShell.Exec("wscript.exe //NOLOGO HTAVBS.vbs")
	  If Err.number <> 0 Then
	    lblStatus.innerText = "Failed to start!"
	  Else
	    lblStatus.innerText = "Started"
	    cmdStart.disabled = True
	    cmdReset.disabled = True
        tmrExternal = _
          window.setInterval("tmrExternal_timer", _
                             1000, _
                             "VBScript")
      End If
    End Sub
    
    Sub cmdReset_onclick()
      lblStatus.innerText = "Ready"
      lblResults.innerHTML = ""
      lblMore.innerHTML = ""
      cmdReset.disabled = True
      cmdStart.disabled = False
    End Sub
    
    Sub Continue()
	  lblMore.innerHTML = _
	      "More, more, more.<BR>" _
	    & "Do some more work in the HTA.<BR>" _
	    & "Work done."
	  cmdReset.disabled = False
    End Sub

    Sub tmrExternal_timer()
      With lblStatus
        If wseExternal.Status = WshRunning Then
          If .className = "clsIndentRed" Then
            .className = "clsIndent"
          Else
            .className = "clsIndentRed"
          End If
        Else
          window.clearInterval tmrExternal
          .innerText = _
              "Finished. Exit code " _
            & CStr(wseExternal.ExitCode)
          .className = "clsIndent"
          Set wseExternal = Nothing
          window.setTimeout "Continue", 200, "VBScript"
        End If
      End With
    End Sub

    Sub window_onload()
      Set wshShell = CreateObject("WScript.Shell")
    End Sub

    Sub window_onunload()
      Set wshShell = Nothing
    End Sub
</SCRIPT>
</HEAD>
<BODY>
  <DIV>
    <INPUT type=button id=cmdStart value="Start WSH Script"> 
    <INPUT type=button id=cmdReset value=Reset disabled>
  </DIV>
  <H3>External task status:</H3>
  <DIV id=lblStatus class=clsIndent>Ready</DIV>
  <H3>More work here in the HTA:</H3>
  <DIV id=lblMore class=clsIndent></DIV>
</BODY>
</HTML>
The [tt]Continue()[/tt] subroutine is just there to perform any synchronous logic you want to run following WSH script completion and clearing of the wait timer.
 
Alas, I left some junk in there when I trimmed this down to a sample.

Delete line 38:

[tt]lblResults.innerHTML = ""[/tt]

Sorry.
 
Thanks for all the responses and the code example guys. I have gone the route of adding additional buttons to the HTA in order to run various processes...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top