DebugSetProcessKillOnExit

The DebugSetProcessKillOnExit function sets or retrieves the value that indicates whether a process is to be terminated when it exits.

This function is part of the Windows Debugging API.

Syntax

C and C++

BOOL DebugSetProcessKillOnExit( HANDLE processHandle, BOOL killOnExit );

Parameters

processHandle

A handle to the process whose exit behavior is to be controlled.

killOnExit

If this parameter is TRUE, the process will be terminated when it exits. If FALSE, the process will not be terminated when it exits.

Return Value

The function returns TRUE if the call is successful, and FALSE if it fails. Errors can be detected by calling DebugGetProcessKillOnExit.

Example

The following C code demonstrates how to set the killOnExit flag to TRUE for a specific process:

#include #include int main() { HANDLE hProcess; DWORD dwExitCode; // Open the process hProcess = CreateProcess("notepad.exe", NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, NULL); if (hProcess != NULL) { // Set kill on exit flag if (DebugSetProcessKillOnExit(hProcess, TRUE)) { printf("Kill on exit set for process.\n"); Sleep(5000); // Wait 5 seconds TerminateProcess(hProcess, 0); } else { printf("Failed to set kill on exit.\n"); } } else { printf("Failed to create process.\n"); } CloseHandle(hProcess); return 0; }