Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Killing a named process

Status
Not open for further replies.

TonyGroves

Programmer
Aug 13, 2003
2,389
IE
Does anybody know how I can kill a named process from a BCB program running on Windows NT? For example, there is a running process called "badproc", and I want to terminate it without further ado.
 
Thanks for that, Wings.

However, TerminateProcess expects to be supplied with a handle to a process, so maybe I should rephrase the question: How do you get a handle to a named process?
 
Howdy,

I wonder if this is what you are looking for?

This is from the MSDN WinAPI Reference:


OpenProcess

The OpenProcess function opens an existing process object.

Code:
HANDLE OpenProcess(
  DWORD dwDesiredAccess,
  BOOL bInheritHandle,
  DWORD dwProcessId
);
Parameters
dwDesiredAccess
[in] Access to the process object. This access right is checked against any security descriptor for the process. This parameter can be one or more of the process access rights.

bInheritHandle
[in] If this parameter is TRUE, the handle is inheritable. If the parameter is FALSE, the handle cannot be inherited.

dwProcessId
[in] Identifier of the process to open.

Return Values
If the function succeeds, the return value is an open handle to the specified process.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.


I hope this is what you need (I dont want to waste anyone's time).

Lood Luck,
onrdbandit
 
Thanks, onrdbandit.

That material is also in the C++Builder online help.
Trouble is, where do I get a process ID for a named process?
 
look into CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 
Ah yes, that look promising!

However, apparently it's not supported by Windows NT, which is what I use.

Thanks anyway, Wings.
 
Howdy,

Chech out this link....
It has an example of a console app in VC++ that displays each process and all the information about them....
Try researching the Process32Next WinAPI function . It returns LPPROCESSENTRY32 object that contains all the information about the process. Including the process id. You could use this to iterate through processes find the one with the correct name then grab the id...

Maybe there is a better way, but I'm stumped...

Good Luck again,
onrdbandit
 
oh wait...

never mind...

the CreateToolhelp32Snapshot function is required to for it to work!

BLAST!

I think you are in a pickle...

Sorry I can't help.
onrdbandit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top