Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to know if my Checkbox is True in VB6.0? 9 65
Authentication of Web Services 3 96
SSRS Deployment problem 5 91
Macro problems with Excel file 6 22
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

685 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