我想运行一个HTA文件,其中有一个循环,其中父HTA调用一个子HTA来显示定期更新。我希望子HTA与旧的更新保持打开,当它再次被新的更新调用时,它应该关闭,然后播放它。我试过这样做,但是我无法在子HTA上添加关闭的HTA条件。这导致所有的儿童HTA在后台打开。
父HTA文件,
以下代码
<html>
<head>
<title>Parent Application</title>
<HTA:APPLICATION
APPLICATIONNAME="Parent Application"
ID="ParentApplication"
VERSION="1.0"/>
</head>
<script language="VBScript">
Sub OnClickButtonConnect()
Dim currentDirectory,pos
pos=InStrRev(document.location.pathname,"\")
currentDirectory=""
If pos>0 Then
currentDirectory = Left(document.location.pathname,pos)
End If
Dim WshShell, i, g
g = 5
set WshShell = CreateObject("wscript.Shell")
For i = 1 To g
cmdline = "mshta.exe """ & currentDirectory & "child.hta"" """ & login.value & """ """ & password.Value & """"
WshShell.Run cmdline,1,False
next
window.close
End Sub
</script>
<body bgcolor="white">
<!--Add your controls here-->
Login:<input type="text" name="login" id="login"><BR>
Password:<input type="password" name="password" id="password"><BR>
<input type="button" name="Connect" id="Connect" value="Connect" onclick="OnClickButtonConnect">
<!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>儿童HTA
<html>
<head>
<title>Child Application</title>
<HTA:APPLICATION
APPLICATIONNAME="Child Application"
ID="ChildApplication"
VERSION="1.0"/>
</head>
<script language="VBScript">
Sub Window_OnLoad
str=""
arguments = Split(ChildApplication.CommandLine," """)
For i=0 To UBound(arguments)
arguments(i)=Replace(arguments(i),"""","")
Next
document.body.innerhtml="login is: " & arguments(1) & "<BR>password is: " & arguments(2)
End Sub
</script>
<body bgcolor="white">
<!--Add your controls here-->
<!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>发布于 2016-05-03 18:58:27
在打开子hta之前调用这个Sub。确保hta的名称与其实际名称相匹配。
Sub CloseChild
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select CommandLine from Win32_Process where CommandLine like '%child.hta%'")
For Each objProcess In colProcessList
objProcess.Terminate()
Next
End Sub编辑:我只是想评论一下以后可能会读到这篇文章的人。将CommandLine放入select语句并不是显式要求的,即使在where子句中使用了该属性。您可以选择流程类中的任何或所有属性,包括或排除CommandLine。
我确实建议只选择提高查询速度所需的属性,为了清晰起见,如果实际上不需要属性,则选择与在where子句中使用的属性相同。
https://stackoverflow.com/questions/37006497
复制相似问题