Reputation: 771
I have created a HTA that will act as an application installer. I need to be able to pass a variable from one function to another, within the HTA. Here's the code:
<!doctype html>
<html>
<script language="vbscript">
set wsh=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
function htaresize
height=480
width=640
window.resizeto width,height
screenheight=document.parentwindow.screen.availheight
screenwidth=document.parentwindow.screen.availwidth
postop=(screenheight-height)/2
posleft=(screenwidth-width)/2
window.moveto posleft,postop
end function
htaresize()
function window_onload
sfl="_a.txt"
set fil=fso.opentextfile(sfl,1)
do until fil.atendofstream
sln=fil.readline
set opt=document.createelement("option")
opt.text=sln
opt.value=sln
availapps.add(opt)
loop
fil.close
end function
function findsel
sel=""
for each i in availapps.options
if i.selected then
sel=sel & i.value
sel=i.value
end if
next
if len(sel)>0 then
select case sel
case "7-Zip"
case "Adobe AIR"
case "Adobe Flash Player"
case "Adobe Acrobat Reader DC"
case "Adobe Shockwave Player"
case "Cisco WebEx"
case "Citrix Receiver"
case "FileZilla"
case "Gimp"
case "Google Chrome"
case "InfraRecorder"
case "FolderSizes"
case "Microsoft Office"
case "Java"
case "Rufus"
end select
if len(sel)>0 then
jpg="<img src='./_dependencies/" & sel & ".jpg'>"
txt="<p>You have chosen to install " & sel & " on this computer.</p>"
war="<p>Please note - If User Account Control (UAC) is active on this system, some functions of this application may be restricted and/or non-functional. If installation fails or the application doesn't function as expected, try temporarily disabling your antivirus or security software and install again as antivirus or other security software could cause the installation to fail.</p><p>Continuing the installation of this software may impair or destabilize the correct operation of this system either immediately or in the future.</p>"
btn="<br><br><input class='button' name='button_cont' onclick='install' type='button' value='INSTALL'>"
end if
dataarea.innerhtml=jpg & txt & war & btn
end if
end function
function install
msgbox sel & " is now being installed. Please wait..."
'* * * perform actual install procedure here * * *
end function
</script>
<hta:application
applicationname="hta"
border="none"
borderstyle="normal"
caption="yes"
contextmenu="no"
commandline=""
icon=""
id="hta"
innerborder="no"
maximizebutton="no"
minimizebutton="no"
navigable="yes"
scroll="no"
scrollflat="yes"
selection="no"
showintaskbar="no"
singleinstance="yes"
systemmenu="no"
version="2016.11.07"
windowstate="normal" />
<head>
<style media="screen" type="text/css">
* {
font:12px "Arial", "Calibri", "Franklin Gothic Book", "Gill Sans MT", "Lucida Sans", "Microsoft Sans Serif", "MS Outlook", "Tahoma", "Verdana" sans-serif;
}
html {
background:#fff;
color:#000;
height:100%;
margin:0;
padding:0;
width:100%;
}
body {
border:1px solid #000;
height:478px;
margin:0;
padding:0;
width:638px;
}
a {
text-decoration:none;
}
div#wrap {
height:100%;
margin:0;
padding:0;
width:100%;
}
div#top {
background-color:#0066cb;
border-bottom:1px solid #000;
color:#000;
height:40px;
margin:0;
overflow:hidden;
padding:5px;
text-align:center;
width:628px;
}
div#top h1 {
font-size:36px;
font-weight:900;
text-align:center;
}
div#left {
background-color:#99cdff;
border-right:1px solid #000;
color:#000;
float:left;
height:385px;
margin:0;
overflow:hidden;
padding:5px;
text-align:center;
width:187px;
}
div#right {
float:right;
height:365px;
margin:0;
overflow:hidden;
padding:10px;
text-align:center;
vertical-align:middle;
width:420px;
}
div#bottom {
background-color:#0066cb;
border-top:1px solid #000;
height:21px;
margin:0;
overflow:hidden;
padding:5px;
text-align:right;
width:628px;
}
span#dataarea {
text-align:center;
padding-top:187px;
}
.right-align {
text-align:right;
}
.coltitle {
font-size:14px;
font-weight:900;
}
.indent {
padding-left:30px;
}
.button {
margin:0;
padding:0;
width:75px;
}
</style>
<title>Application Installer</title>
</head>
<body>
<div id="wrap">
<div id="top">
<h1 class="right-align">APPLICATION INSTALLER</h1>
</div>
<div id="left">
<br />
<p class="coltitle">Available Applications</p>
<select id="listbox" size="18" name="availapps"></select>
<br /><br />
<input class="button" name="select" type="button" onclick="findsel" value="SELECT">
</div>
<div id="right">
<span id="dataarea"></span>
</div>
<div id="bottom">
<input class="button" name="button_exit" onclick="window.close" type="button" value="EXIT">
</div>
</div>
</body>
</html>
Therefore, the goal is to be able to read the "sel" variable, established within the "findsel" function, from within the "install" function.
Is this possible?
Thanx in advance!
Upvotes: 1
Views: 676
Reputation: 771
Figured it out. At the beginning of the script section, prior to any of the functions, I added...
dim choice
Then, in the "findsel" function, I added...
choice=sel
Finally, in the "install" function, I modified...
msgbox sel & " is now being installed. Please wait..."
To...
msgbox choice & " is now being installed. Please wait..."
Thanx.
Upvotes: 1