如何将变量值传递给HTA

时间:2017-12-04 11:20:03

标签: javascript batch-file hta

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

我该怎么做?

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

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:3)

以下是使用hta应用程序对象的命令行属性的Microsoft示例。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="search-form searchbar" role="search" id="hiddenSearchBox" action="" method="POST">
    <div class="input-group">
        <input type="hidden" name="id" value="63">
        <input type="search" name="keywords" class="form-control" placeholder="Search..">
        <div class="input-group-btn">
            <button type="submit" class="btn btn-default" data-toggle="searchbar" data-target="#hiddenSearchBox">
                <span class="glyphicon glyphicon-search"></span> <span class="sr-only">Submit</span>
            </button>
        </div>
    </div>
</form>
<button id="hide_form">
    Hide Form
</button>

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