I've got an HTA that offers the ability to open 3 other HTAs. On the "Close" button of the main HTA, I want all 4 HTAs to close. I'm using the code below, but the problem is when I run it, the main HTA closes right away, before it has a chance to close the 3 "child" HTAs, so they remain open. Is there some way to indicate that the processes opened later should be closed first and the "main" process should be closed last?
Code:
Sub ExitProgram
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'mshta.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
End Sub