How to programatically terminate an .exe?

H

hommer

Hi, evryone,
I am working on a solution that will terminate an exe app written in VB6
programatically. I am able to use the shell function in vb to start it, and
get an task ID for the thread(?). Now when I call the API listed below, it
failed to get a handle on the process.

I know this is more about windows API programing, and I could not find a
btter forum to ask for help. I am grateful if you can help, or point me to
the right resource.

Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
 
K

Kim Greenlee

Hommer,

To kill a process you need the process id not the task id. When the
operating system starts a program it creates a thread that the program runs
on and a process space (memory and some data structures) that the program is
started in. You need the process id for the VB6 application you started.

If you are having trouble determining which id is which you can cheat a
little to help you debug. After you've collected your id(s), set a break
point. Open the 'Windows Task Manager', change the settings so you can see
the PID, look for your VB6 app, and look at the PID. Then go back to your
code and see which number matches. This is a cheat.

You could also actually publish the code you use to start the process and
the kill code so that we can see exactly what you're doing.

Good luck,

Kim Greenlee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top