diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-12 15:00:36 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-12 15:00:36 +0100 |
commit | 1baddad5993f4bbbfe4e8486d44ea070d310431d (patch) | |
tree | 3a3352feeaeaf21d096a57abdc853a8acde93f47 | |
parent | 312703ca1f733b70810d55a5710660452147ccbc (diff) | |
parent | 01adf738fab649d883a2d892588506758fdb28a2 (diff) |
Merge pull request #71269 from bruvzg/win_kill
[Windows] Allow OS::kill method to terminate non-child processes.
-rw-r--r-- | platform/windows/os_windows.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index bc74978f0b..b3831573cf 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -718,15 +718,23 @@ Error OS_Windows::create_process(const String &p_path, const List<String> &p_arg } Error OS_Windows::kill(const ProcessID &p_pid) { - ERR_FAIL_COND_V(!process_map->has(p_pid), FAILED); + int ret = 0; + if (process_map->has(p_pid)) { + const PROCESS_INFORMATION pi = (*process_map)[p_pid].pi; + process_map->erase(p_pid); - const PROCESS_INFORMATION pi = (*process_map)[p_pid].pi; - process_map->erase(p_pid); + ret = TerminateProcess(pi.hProcess, 0); - const int ret = TerminateProcess(pi.hProcess, 0); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } else { + HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, false, (DWORD)p_pid); + if (hProcess != NULL) { + ret = TerminateProcess(hProcess, 0); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); + CloseHandle(hProcess); + } + } return ret != 0 ? OK : FAILED; } |