Solved

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

Posted on 2004-09-24
4
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

729 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