|
|
PROG |
| 22 Haz 2001 | KILL PROCESS BY NAME | VC++ Articels |
|
(works in:
Microsoft Windows 95/98/ME/NT/2000) It is sometimes
necessary to terminate a running process in MS-Windows. The Win32 API provides the
TerminateProcess function for this, but it requires a "handle to the process".
In many cases it is not apparent how to get this handle if all you know is the process
name. The following routine lets you get around this problem. The routine is
named KILL_PROC_BY_NAME, and is available as part of the C++ source file EXAM28.CPP. The
routine has the following calling parameters: int
KILL_PROC_BY_NAME(char *) where the process
name is supplied as a zero-terminated C char string and it returns an integer completion
code. You can download
the file in ZIP format by clicking on the following link. Download Exam28.zip
(3 kB, last modified: 12/29/2000) This works for
Microsoft Windows 95/98/ME/NT/2000. I have tested with Visual C++ v6.0 but it should work
with other versions also. Please let me know of exceptions. After downloading,
unzip the file Exam28.cpp into any folder. It contains a short console mode program which
demonstrates how to call KILL_PROC_BY_NAME to terminate the NotePad program. Note: This routine
uses the Windows API function TerminateProcess to terminate the process. This may not be
suitable for all purposes. In particular, note the following remarks from the MSDN
description of TerminateProcess. Remarks (on TerminateProcess) |
|
|
|
home | about me | links | projects | clean energy | programming | |