如何将变量值传递给 HTA

How to pass variable value to HTA

批处理文件中的以下代码通过 HTA 对话框从用户处获取密码。它工作正常。我想传递一个变量值 !user[%%a]!显示在弹出的 HTA 对话框中,这样我就可以看到 输入用户 ID 的密码: "BATCH FILE USER VARIABLE" 在这个 window 中:

我该怎么做?

<!-- :
@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>

我总是很高兴看到我的脚本被使用 :)。试试这个修改:

<!-- :
@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>

这是一个使用 hta 应用程序对象的命令行 属性 的 Microsoft 示例。

<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>

编写 HTML Internet Explorer 5.0 应用程序,Scott Roberts,MSDN Library 2001。