Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA to kill self and other HTA Processes

Status
Not open for further replies.

cwsstins

MIS
Aug 10, 2004
412
US
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
 
Code:
For Each oProcess in cProcessList
  sCommLine = LCase(oProcess.CommandLine)
  If InStr(sCommLine, "your.hta") = 0 Then
    oProcess.Terminate()
  End If
Next
Window.Close

If you don't want to hardcode the "your.hta" you can check if the command line for the process matches your oHtaId.commandLine. If it were me, I'd check the command line for each hta to make sure it's one I want to close.

A better option is to open the other HTAs as modal or modeless. Then they're tied to the original window. If the original window closes, then they both close.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top