Windows API - program ID's

BlitzMax Forums/BlitzMax Programming/Windows API - program ID's

xlsior(Posted 2006) [#1]
I am trying to come up with a way to kill specific processes, and cobbled together the following which is largely based on something by Sweenie... However, I am running into a snag that the PID returned by the code does not match up with the actual PID used by the program as shown by TaskManager.

If I use the taskmanager PID's I can successfully terminate a process, but for whatever reasons the PID's returned by the program below seem to be off a couple... Most of the time the returned value is off by 4, but it's not consistent -- sometimes it's off by 8, or even more than a hundred. There's definitely something not right, but for the life of me I can't figure out what it is.

Is there anyone who can offer some pointers to what I'm doing wrong?




JoshK(Posted 2006) [#2]
Use pub.freeprocess.


xlsior(Posted 2006) [#3]
(Oops, looks like my initial posting got chopped off. Fixed)

Use pub.freeprocess


I looked at that, but didn't see a way to kill an arbitrary process that wasn't launched through Blitzmax itself first... The problem is getting the process ID for the other program, not killing the process once I have it.


ziggy(Posted 2006) [#4]
@xlsior: I'm not sure if vista will let any application terminate a process it has not started... I think it will be considered a security violation by the OS.


xlsior(Posted 2006) [#5]
I'm not sure if vista will let any application terminate a process it has not started... I think it will be considered a security violation by the OS.


You're probably right, but this is for something I'm mainly writing for personal use, and I have no intention of downgrading to Vista any time soon...

And killing the process works fine with the code above under XP, the only problem I have is to programmatically get the correct process ID. If I look it up in taskmanager and feed that to the KillProcess function, it works like a charm.


REDi(Posted 2006) [#6]
lpdwProcessId param returns the Process ID that you need to use.


The one you was using is a Thread ID.


xlsior(Posted 2006) [#7]
Aha! thank you so much!

The Win32 API sure isn't very easy to get started with. :-?


REDi(Posted 2006) [#8]
np mate