2016-05-03 21 views
0

我想運行一個HTA文件,其中有一個父HTA調用一個子HTA以定期顯示更新的循環。我希望孩子的HTA在舊版本中保持打開狀態,並且在新的更新中再次調用它時應該關閉,然後重新啓動它。我試圖做到這一點,但我無法爲孩子HTA添加密切的HTA條件。這導致所有Child 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> 
+0

任何一個請幫忙 –

+0

嘗試編輯您的問題併發布您的HTA代碼! – Hackoo

+0

您可以將命令行添加到您的WMI查詢中的子HTA中,以選擇要關閉的進程嗎? '從Win32_Process中選擇*其中的CommandLine像'%'child.hta%'' – langstrom

回答

1

調用此子。確保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子句中。您可以選擇Win32_Process課程中的任何或所有屬性,包括或不包括CommandLine

我建議只選擇你需要增加查詢的速度,和歷史,爲清楚起見,我選擇了相同的屬性,因爲我的where子句中使用屬性,如果我實際上並不需要一個

+0

它的工作,非常感謝您的幫助。 –