I have a very basic HTA form with a checkbox and a button. I am trying to pass the checkbox status using VBScript in my HTA to a PowerShell script, which is called when the button is clicked. Unfortunately, I am unable to pass the value of the parameter through. It keeps coming across as empty.
Code in HTA:
<html>
<head>
<title>Test Form</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<hta:application applicationname="Proof of concept version="1.0" />
<script language="vbscript">
Sub Resize()
window.resizeTo 500,450
End Sub
Sub ExecutePowerShell()
Dim oShell, scriptPath, appCmd, retVal, retData, isTestCheckBoxChecked
'Collect value from input form
isTestCheckBoxChecked = document.getElementByID("input_checkBoxTest").checked
MsgBox isTestCheckBoxChecked
Set oShell = CreateObject("Wscript.Shell")
Set scriptPath = ".\TestPowershell.ps1 -isTestCheckBoxChecked " & isTestCheckBoxChecked
appCmd = "powershell.exe " & scriptPath
retVal = oShell.Run(appCmd, 1, true)
retData = document.parentwindow.clipboardData.GetData("text")
End Sub
</script>
</head>
<body onload="Resize()">
<h1>Test Form:</h1>
<div style="margin-top:10px; margin-bottom:30px;">
The scipt does the following checks:
<ul>
<li><input name="input_checkBoxTest" type="checkbox" checked="checked"/> This is a test textbox</li>
</ul>
</div>
<br /><br />
<input type="button" id="btn_execute" value="Execute" onclick="ExecutePowerShell()" />
<br /><br />
</body>
</html>
Powershell script:
#Param([Parameter(Mandatory=$true)][bool]$isTestCheckBoxChecked)
Write-host "The value is '$isTestCheckBoxChecked'"
The output I get is:
"The value is ''"
Any guidance will be appreciated.