Solved

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

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

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
VB6 ListBox Question 4 61
Developing a front end to SPLUNK 1 100
Win 10 Automation Error with .doCmd in Access 2 80
What are MicroServices? 4 65
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
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…

738 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