Reputation: 177
The following code in a batch file which gets the password from user Thru a HTA dialog box. It works fine. I want to pass a variable value !user[%%a]! to be displayed inside the pop up HTA dialog box so I can see
Enter password for User ID: "BATCH FILE USER VARIABLE"
in this window :
How can I do that?
<!-- :
@setlocal enableextensions enabledelayedexpansion
:: PasswordSubmitter.bat
@echo off
set user[1]=me1
set user[2]=me2
set user[3]=me3
for /l %%a in (1,1,3) do (
set counter=%%a
for /f "tokens=* delims=" %%p in ('mshta.exe "%~f0"') do (
set pass[!counter!]=%%p
)
echo Password for User-!user[%%a]! is "!pass[%%a]!"
)
endlocal
exit /b
<html>
<HEAD><title>Password submitter</title>
<HTA:APPLICATION INNERBORDER="no" SYSMENU="no" SCROLL="no" >
<style type="text/css">
body {
color: white;
background: black;
font-family: "Calibri", monospace;
}
</style>
</HEAD>
<body>
<p>Enter password for User ID</p>
<script language='javascript' >
window.resizeTo(400,200);
function pipePass() {
var pass=document.getElementById('pass').value;
var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
close(fso.Write(pass));
}
</script>
<input type='password' name='pass' size='16'></input>
<hr>
<button onclick='pipePass()'>Submit</button>
</body>
</html>
Upvotes: 2
Views: 2973
Reputation: 57262
I'm always happy to see my scripts used :). Try this modification:
<!-- :
@setlocal enableextensions enabledelayedexpansion
:: PasswordSubmitter.bat
@echo off
set user[1]=me1
set user[2]=me2
set user[3]=me3
for /l %%a in (1,1,3) do (
set counter=%%a
for /f "tokens=* delims=" %%p in (' echo %%user[!counter!]%%^|mshta.exe "%~f0"') do (
set pass[!counter!]=%%p
)
echo Password for User-!user[%%a]! is "!pass[%%a]!"
)
endlocal
exit /b
<html>
<HEAD><title>Password submitter</title>
<HTA:APPLICATION INNERBORDER="no" SYSMENU="no" SCROLL="no" >
<style type="text/css">
body {
color: white;
background: black;
font-family: "Calibri", monospace;
}
</style>
</HEAD>
<body>
<p>Enter password for {User ID}</p>
<script language='javascript' >
window.resizeTo(400,200);
//var sh = new ActiveXObject( 'WScript.Shell' );
var input= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0);
var user=input.ReadLine();
document.body.innerHTML = document.body.innerHTML.replace('{User ID}', user);
function pipePass() {
var pass=document.getElementById('pass').value;
var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
close(fso.Write(pass));
}
</script>
<input type='password' name='pass' size='16'></input>
<hr>
<button onclick='pipePass()'>Submit</button>
</body>
</html>
Upvotes: 6
Reputation: 540
Here's a Microsoft example of using the commandline property of the hta application object.
<HTML>
<HEAD>
<TITLE>Scripting the HTA:APPLICATION Tag</TITLE>
<HTA:APPLICATION
ID="oHTA"
> <SCRIPT LANGUAGE="VBScript">
Option Explicit Dim cmdLineArray
Dim strHello ' This code assumes that you have no spaces in
' the path to Hello.hta. (In other words, this code
' splits the command line by spaces and assumes
' that your name is the second word.)
'
cmdLineArray = Split(oHTA.commandLine)
strHello = "Hello " & cmdLineArray(1) & ", " _
& "How are you?" MsgBox strHello
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
Writing HTML Applications for Internet Explorer 5.0, Scott Roberts, MSDN Library 2001.
Upvotes: 3