Solved

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

Posted on 2004-09-24
4
225 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

810 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