TerminateProcess
bool TerminateProcess(int processID)Description
Forcefully terminates a running process identified by its process ID (PID).
This function opens the process with PROCESS_TERMINATE access, calls TerminateProcess, and waits up to 5 seconds for the process to exit.
Unlike SendMessage with WM_CLOSE, this method does not require a visible window handle and works reliably with processes that have no visible top-level window, use child windows, tool windows, or render directly to the desktop.
Parameter
- processID - The process ID (PID) of the target process, typically obtained via GetProcessID().
Return
- bool - true if the process was successfully terminated, otherwise false.
Example
void main()
{
int pid = GetProcessID("Deskora.exe");
if (pid != 0)
{
bool ok = TerminateProcess(pid);
if (ok)
Print("Process terminated successfully");
}
}