Solved

Closing releated ExEs on closinf of a particular exe by Visual Basic

Posted on 2004-09-24
4
218 Views
Last Modified: 2013-11-25
i am running 11 diifrent EXEs  from a main exe using shell command.
i want to close all associate Exe on closing of main exe.
How can i do it by Visual Basic
0
Comment
Question by:amit_mi2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12149596
When this app opens it will load up 11 instances of calculator.  When it closes, it closes all of them using the OpenProcess() and TerminateProcess() APIs.

Regards,

Idle_Mind

Option Explicit

Private Const PROCESS_ALL_ACCESS = &H1F0FFF

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess _
    As Long, ByVal uExitCode As Long) As Long

Private PIDs As Collection

Private Sub Form_Load()
    Dim i As Integer
    Dim pid As Long
   
    Set PIDs = New Collection
    For i = 1 To 11
        pid = Shell("calc.exe", vbNormalFocus)
        PIDs.Add pid
    Next i
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim pid As Variant
    Dim lngProcess
   
    For Each pid In PIDs
        lngProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, CLng(pid))
        If lngProcess <> 0 Then
            Call TerminateProcess(lngProcess, 0&)
        End If
    Next pid
End Sub
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now