Solved

Passing variables between pages (hta/vbs)

Posted on 2010-09-22
16
638 Views
Last Modified: 2012-05-10
Hi guys,

Id like to use vbscript (hta) to build the following web pages.

Web page       Action to do on this page
==========================================
Web page 1      Choose Computer type: (laptop or desktop)
Web page 2      Choose Build type: (build or rebuild)
Web page 3      Choose Country: (countries listed in a select box)
Web page 4      Selection Summary: Display options chosen (then confirm y/n to continue)


So, basically, id love some help on how to contruct these web/hta pages so that on web page 4, I would have something like below:

--------------------------------------------------------------- webpage4.hta

You have selected the following options:

Computer type:  desktop (or laptop, depending on what was chosen on web page 1)
Build type: build (or rebuild, depending on what was chosen on web page 2)
Country: Australia (or whatever country selected on web page 3)

Confirmation:
Press the yes button to proceed or the no button to abort.




Any help on this greatly appreciated.

0
Comment
Question by:Simon336697
  • 8
  • 8
16 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 33739775
Hi Simon, this could probably be done all on one page, as you're not presenting that much info each time....what would actually happen when the user clicks "Yes" at the end?  Or do you have that part handled?

Regards,

Rob.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 33762516
Hi Rob,

Hope you are well Rob.
I have that part handled Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33763255
OK sure.  I'll knock up a quick HTA for you tomorrow then.

Rob.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 33765911
Thanks so much Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33766507
OK, here's a quick effort.  You will see when you click Run, it picks up the "value" from the combo boxes.

Regards,

Rob.
<html>

<head>

<title>Request Details</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Request Details"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

 

<script language="VBScript">

 

Dim strHTAPath

 

Sub Window_onLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

	If Mid(document.location, 6, 3) = "///" Then

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	Else

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	End If

End Sub

 

Sub Run_Program

	MsgBox "Computer Type: " & cboComputerType.Value & VbCrLf & _

		"Build Type: " & cboBuildType.Value & VbCrLf & _

		"Country: " & cboCountry.Value

End Sub

 

</script>

</head>

<body style="background-color:#B0C4DE">

        <table width='90%' height='90%' align='center' border='0'>

                <tr>

                        <td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">

                                Request Details

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Computer Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboComputerType" id="cboComputerType">

                                	<option id="optComputerType" value="Laptop">Laptop</option>

                                	<option id="optComputerType" value="Desktop">Desktop</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Build Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboBuildType" id="cboBuildType">

                                	<option id="optBuildType" value="Build">Build</option>

                                	<option id="optBuildType" value="Rebuild">Rebuild</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Country: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboCountry" id="cboCountry">

                                	<option id="optCountry" value="Australia">Australia</option>

                                	<option id="optCountry" value="New Zealand">New Zealand</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='center'>

                                <input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

                        </td>

                        <td align='center'>

                                <input type="button" value="Exit" name="btn_exit" onClick="vbs:window.close" style="font-size: 16px;"><br><br>

                        </td>

                </tr>

        </table>

</body>

</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 33783977
Hi Rob,
This is great.

Rob, can I ask you.

When you click on the run button, which has code:

<input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

and runs the Run_Program sub as follows:

Sub Run_Program
      MsgBox "Computer Type: " & cboComputerType.Value & VbCrLf & _
            "Build Type: " & cboBuildType.Value & VbCrLf & _
            "Country: " & cboCountry.Value
End Sub


This has on button, an ok button.

Is there a way to:
1.Add a second button for cancel, so that if the user presses this, it resets the 3 select boxes on the page?
2.If they click on OK, it fires off a batch file that launches notepad?

Thanks so much for your help.

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33784240
Sure, try this.

Regards,

Rob.
<html>

<head>

<title>Request Details</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Request Details"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

 

<script language="VBScript">

 

Dim strHTAPath

 

Sub Window_onLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

	If Mid(document.location, 6, 3) = "///" Then

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	Else

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	End If

End Sub

 

Sub Run_Program

	If cboComputerType.Value = "NONE" Then

		MsgBox "Please select a computer type."

		cboComputerType.Focus

	ElseIf cboBuildType.Value = "NONE" Then

		MsgBox "Please select a build type."

		cboBuildType.Focus

	ElseIf cboCountry.Value = "NONE" Then

		MsgBox "Please select a country."

		cboCounty.Focus

	Else

		intReturn = MsgBox("Selected Options:" & VbCrLf & "Computer Type: " & cboComputerType.Value & VbCrLf & _

			"Build Type: " & cboBuildType.Value & VbCrLf & _

			"Country: " & cboCountry.Value & VbCrLf & VbCrLf & _

			"Do you want to continue?", vbYesNo, "Confirmation")

		If intReturn = vbYes Then

			MsgBox "Running"

		Else

			cboComputerType.Value = "NONE"

			cboBuildType.Value = "NONE"

			cboCountry.Value = "NONE"

			MsgBox "You cancelled the operation."

		End If

	End If

End Sub

 

</script>

</head>

<body style="background-color:#B0C4DE">

        <table width='90%' height='90%' align='center' border='0'>

                <tr>

                        <td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">

                                Request Details

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Computer Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboComputerType" id="cboComputerType">

                                	<option id="optComputerType" value="NONE"> --- Select --- </option>

                                	<option id="optComputerType" value="Laptop">Laptop</option>

                                	<option id="optComputerType" value="Desktop">Desktop</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Build Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboBuildType" id="cboBuildType">

                                	<option id="optBuildType" value="NONE"> --- Select --- </option>

                                	<option id="optBuildType" value="Build">Build</option>

                                	<option id="optBuildType" value="Rebuild">Rebuild</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Country: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboCountry" id="cboCountry">

                                	<option id="optCountry" value="NONE"> --- Select --- </option>

                                	<option id="optCountry" value="Australia">Australia</option>

                                	<option id="optCountry" value="New Zealand">New Zealand</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='center'>

                                <input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

                        </td>

                        <td align='center'>

                                <input type="button" value="Exit" name="btn_exit" onClick="vbs:window.close" style="font-size: 16px;"><br><br>

                        </td>

                </tr>

        </table>

</body>

</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 33787468
Hi Rob,

thanks so much again.

Rob,

If I paste all your code in a file called 'test.hta', I get the following message if I fail to select an entry for the Country select box.
Line: 37
Error: Object required: 'cboCounty'
This does not happen if I deliberatly test not selecting an entry for the other 2 select boxes.

The funny thing is, is that if I paste all your code in a file called 'test.html', I dont get any error messages like those above.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:Simon336697
ID: 33787484
Rob please disregard my last question. Found the problem.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33787498
Oh sorry....this line
            cboCounty.Focus

should have been
            cboCountry.Focus

Forgot the "r"....

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33787500
Hmmm, it's lucky I didn't forget a different letter ;-)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 33787555
Rob,

Is there a way for example, removing the following lines:

                                <select size="1" name="cboCountry" id="cboCountry">
                                      <option id="optCountry" value="NONE"> --- Select --- </option>
                                      <option id="optCountry" value="Australia">Australia</option>
                                      <option id="optCountry" value="New Zealand">New Zealand</option>
                                </select>

and get the hta to read a text file called 'countries.txt' to load the combo box options?
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 33794361
Yep, sure.  This will read from a file called Countries.txt in the same folder as the HTA file.

Regards,

Rob.
<html>

<head>

<title>Request Details</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Request Details"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

 

<script language="VBScript">

 

Dim strHTAPath

 

Sub Window_onLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

	If Mid(document.location, 6, 3) = "///" Then

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	Else

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	End If

	Populate_Countries

End Sub

 

Sub Populate_Countries

	Set objFSO = CreateObject("Scripting.FileSystemObject")

	Const intForReading = 1

	strCountriesFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "Countries.txt"

	Set objCountries = objFSO.OpenTextFile(strCountriesFile, intForReading, False)

	While Not objCountries.AtEndOfStream

		strCountry = Trim(objCountries.ReadLine)

		If strCountry <> "" Then

			Set objOption = Document.CreateElement("OPTION")

			objOption.Text = strCountry

			objOption.Value = strCountry

			cboCountry.Add(objOption)

		End If

	Wend

	objCountries.Close

End Sub



Sub Run_Program

	If cboComputerType.Value = "NONE" Then

		MsgBox "Please select a computer type."

		cboComputerType.Focus

	ElseIf cboBuildType.Value = "NONE" Then

		MsgBox "Please select a build type."

		cboBuildType.Focus

	ElseIf cboCountry.Value = "NONE" Then

		MsgBox "Please select a country."

		cboCountry.Focus

	Else

		intReturn = MsgBox("Selected Options:" & VbCrLf & "Computer Type: " & cboComputerType.Value & VbCrLf & _

			"Build Type: " & cboBuildType.Value & VbCrLf & _

			"Country: " & cboCountry.Value & VbCrLf & VbCrLf & _

			"Do you want to continue?", vbYesNo, "Confirmation")

		If intReturn = vbYes Then

			MsgBox "Running"

		Else

			cboComputerType.Value = "NONE"

			cboBuildType.Value = "NONE"

			cboCountry.Value = "NONE"

			MsgBox "You cancelled the operation."

		End If

	End If

End Sub

 

</script>

</head>

<body style="background-color:#B0C4DE">

        <table width='90%' height='90%' align='center' border='0'>

                <tr>

                        <td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">

                                Request Details

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Computer Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboComputerType" id="cboComputerType">

                                	<option id="optComputerType" value="NONE"> --- Select --- </option>

                                	<option id="optComputerType" value="Laptop">Laptop</option>

                                	<option id="optComputerType" value="Desktop">Desktop</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Build Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboBuildType" id="cboBuildType">

                                	<option id="optBuildType" value="NONE"> --- Select --- </option>

                                	<option id="optBuildType" value="Build">Build</option>

                                	<option id="optBuildType" value="Rebuild">Rebuild</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Country: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboCountry" id="cboCountry">

                                	<option id="optCountry" value="NONE"> --- Select --- </option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='center'>

                                <input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

                        </td>

                        <td align='center'>

                                <input type="button" value="Exit" name="btn_exit" onClick="vbs:window.close" style="font-size: 16px;"><br><br>

                        </td>

                </tr>

        </table>

</body>

</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 33821161
Thanks Rob that is brilliant. Sorry about the delay.
Thanks again works great mate. Take care and talk soon.
0
 
LVL 1

Author Closing Comment

by:Simon336697
ID: 33821165
Brilliant as usual Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33826535
No problem. Thanks for the grade.

Rob.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now