Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This forum is the most helpful site I've ever used. I used to use Deja.com; but, this site is better - hands down!..."

Geography

Where in the world do Tek-Tips members come from?
Bubbler (IS/IT--Management)
20 Jan 04 1:10
Lets say there is a process running called myprocess.exe that was launched by my app (not in the applications window, in the processes window) Can I check for and kill it on exit of my app? I say check for, because it may or may not be running depending on user input. And can it be done across (x, 2000 XP etc?

Helpful Member!(2)  vb5prgrmr (Programmer)
20 Jan 04 6:58

Bubbler, a quick search in your forums for any date using all words on the words of process you would have found the following threads on the first page of the results.

Killing Processes Thread222-730420

Find a Process not a window. Thread222-460991

Stop applications from running Thread222-716715

How to close a program thru code Thread222-77760

Kill process using PID Thread222-683642

and if you would have done the whole site this would have come up somewhere also

Ending Unmanaged Processes Thread796-715271

Good Luck

Helpful Member!(2)  Hypetia (Programmer)
20 Jan 04 7:00
This is easy if you launch the external process myprocess.exe from Shell function.

See the following code. Place a command button on the form and run the following code.
___

Option Explicit
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const PROCESS_TERMINATE As Long = &H1&
Dim idProcess As Long
Private Sub Command1_Click()
    On Error Resume Next
    AppActivate idProcess
    If Err Then idProcess = Shell("calc.exe", vbNormalFocus)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim hProcess As Long
    hProcess = OpenProcess(PROCESS_TERMINATE, 0, idProcess)
    TerminateProcess hProcess, 0
    CloseHandle hProcess
End Sub

___

Clicking the button will start Calculator application. If you close your program, Calculator will also close if it is running.
SkennyR (Programmer)
11 Apr 04 9:57
Hi...
I tried your method Hypetia, and it works great.
I want to be able to start and end the external program from my main program. However, if I close the main program, I want the external program to continue running.
I added another command button to the form and replaced your "Private Sub Form_Unload(Cancel As Integer)" with
"Private sub Command2_Click()".
The main program starts and stops the external program, and the external program continues to run when I close the main program.
My problem is that when I re-open the main program, it will not stop the external program. I can restart another instance of the external program and end it, but the first instance of the external program can not be stopped from the re-opened main program.
Why is this?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close