首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果子HTA文件从父HTA文件中再次调用,则关闭它的方法

如果子HTA文件从父HTA文件中再次调用,则关闭它的方法
EN

Stack Overflow用户
提问于 2016-05-03 14:05:58
回答 1查看 637关注 0票数 0

我想运行一个HTA文件,其中有一个循环,其中父HTA调用一个子HTA来显示定期更新。我希望子HTA与旧的更新保持打开,当它再次被新的更新调用时,它应该关闭,然后播放它。我试过这样做,但是我无法在子HTA上添加关闭的HTA条件。这导致所有的儿童HTA在后台打开。

父HTA文件,

以下代码

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-03 18:58:27

在打开子hta之前调用这个Sub。确保hta的名称与其实际名称相匹配。

代码语言:javascript
复制
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子句中使用的属性相同。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37006497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档