是否可以批量调用多个HTA-APP?
我有几页的HTA,我想从一批中的不同地方调用。
例如:
<!-- :: Batch section
@echo off
setlocal enableextensions disabledelayedexpansion
for /F "tokens=1,2 delims=|" %%a in ('mshta.exe "%~F0"') do (
set "field1=%%a"
set "field2=%%b"
)
echo %field1%
echo %field2%
set var=hallo
for /F "delims=" %%a in ('mshta.exe "%~F0" %var%') do set "HtaResult=%%a"
echo Result = %HtaResult%
echo End of HTA window
pause
goto :EOF
问题是我想批量调用两个HTA。 目前,我始终只调用第一个HTA。有可能吗?
答案 0 :(得分:1)
在上一个问题的模式下
<!-- :: Batch section
@echo off
setlocal enableextensions disabledelayedexpansion
rem use command line arguments to tell the hta what to do
rem Defined which tokens we need and the delimiter between them
for /F "tokens=1,2 delims=|" %%a in ('mshta.exe "%~F0" test1') do (
set "field1=%%a"
set "field2=%%b"
)
echo End of HTA 1 window, reply: "%field1%" "%field2%"
for /F "tokens=1" %%a in ('mshta.exe "%~F0" test2') do (
set "field1=%%a"
)
echo End of HTA 2 window, reply: "%field1%"
pause
goto :EOF
-->
<HTML>
<HEAD>
<!-- you will need to give an ID to the HTA -->
<HTA:APPLICATION SCROLL="no" SYSMENU="no" ID="thisHTAID" >
<TITLE>HTA Buttons</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(374,400);
// function handling test1 hta output
function myFunction() {
new ActiveXObject("Scripting.FileSystemObject")
.GetStandardStream(1)
.WriteLine(
[ // Array of elements to return joined with the delimiter
document.getElementById("myText").value
, document.getElementById("myText2").value
].join('|')
);
window.close();
};
// functio handling test2 hta output
function myButton( selected ){
new ActiveXObject("Scripting.FileSystemObject")
.GetStandardStream(1)
.WriteLine( selected );
window.close()
};
// on window load select what div to show depending on command line
window.onload = function(){
var commandLine = thisHTAID.commandLine;
commandLine = commandLine.substr(
self.location.pathname.length
+ ( commandLine.substr(0,1) === '"' ? 2 : 0 )
).replace(/^\s+/g,'');
document.getElementById( commandLine ).style.display='block';
};
</SCRIPT>
</HEAD>
<BODY>
<!-- hide hta screens inside div tags -->
<div id="test1" style='display:none'>
<h3>A demonstration of how to access a Text Field</h3>
<input type="text" id="myText" value="0123">
<input type="text" id="myText2" value="4567">
<p>Click the "Login" button to get the text in the text field.</p>
<button onclick="myFunction()">Login</button>
</div>
<div id="test2" style='display:none'>
<h3>Just another demostration</h3>
<button onclick="myButton(1)">button1</button>
<button onclick="myButton(2)">button2</button>
</div>
</BODY>
</HTML>
代码注释中公开的基本思想是根据调用HTA时给出的命令行参数来确定显示哪一层