Correct me if I am wrong : you have an application which starts 2 other processes (of which you don't have access to the source code), and you want those 2 processes to be killed when your application ends ?
This can be done when your application starts an extra process which monitors the state of your application and takes care of closing the other 2 processes
for example a rough monitoring application could exist of 1 module :
Option Explicit
Public pstrArg() As String
Private Sub Main()
pstrArg = Split(Command, " ")
Load frmMonitor
End Sub
This module loads a form called frmMonitor with a timer control on it :
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Form_Load()
With Timer1
.Interval = 100
.Enabled = True
End With 'Timer1
End Sub
Private Sub Timer1_Timer()
Dim intIndex As Integer
If FindWindow(vbNullString, pstrArg(0)) = 0 Then
For intIndex = 1 To UBound(pstrArg)
TerminateProcess pstrArg(intIndex)
Next intIndex
End
End If
End Sub
Private Sub TerminateProcess(strName As String)
Dim Process As Object
For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = '" & strName & "'")
Process.Terminate
Next
End Sub
Make sure the startup function of the monitoring application is sub Main so you can call it with command line arguments
You can test this as follows :
compile the monitoring application into MonitorApp.exe and place it in the same folder as a test project existing of 1 form named frmTest :
'1 form with:
' 1 timer control: name=Timer1
' 1 command button : name=Command1
Option Explicit
Private Sub Command1_Click()
Shell "calc.exe"
End Sub
Private Sub Form_Load()
Shell App.Path & "\MonitorApp.exe frmTest calc.exe"
End Sub
This will start a calculator each time you click on the command button
When you close the form, the monitor application will close all calculators, and then finish itself