Skip to content

add win32 kill api - #1716

Closed
xoviat wants to merge 6 commits into
GuillaumeGomez:mainfrom
xoviat:win32-kill
Closed

add win32 kill api#1716
xoviat wants to merge 6 commits into
GuillaumeGomez:mainfrom
xoviat:win32-kill

Conversation

@xoviat

@xoviat xoviat commented Aug 17, 2026

Copy link
Copy Markdown

use the win32 api to kill the process if possible, and add ability to stop and resume process.

Comment thread tests/process.rs
process.wait();

#[cfg(windows)]
std::thread::sleep(std::time::Duration::from_millis(150));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reason: the new method kills the process much faster than before, so the OS info is not yet updated when the information is refreshed.

Comment thread src/windows/process.rs Outdated
use windows::core::PCWSTR;
use windows::core::{PCSTR, s, w};

type NtSuspendProcess = unsafe extern "system" fn(HANDLE) -> i32;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed all Nt* calls because some windows antivirus are very unhappy about them. Not sure it's a good idea to try to reintroduce them.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternatives to these functions would make implementation of the pause/resume functionality difficult. If they are only used for that functionality, would the antivirus trigger if they are never used? The alternative is to suspend the threads one by one which is more involved or not attempt this at all, which would constrain this to pr to trying TerminateProcess.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is actually the current code: to not support these features.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the ntdll calls. The only thing left is TerminateProcess. If that is too much, I will close the PR.

Comment thread src/windows/process.rs
PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
| PROCESS_SUSPEND_RESUME
| PROCESS_TERMINATE,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you absolutely need PROCESS_TERMINATE, then use OpenProcess directly in kill_with_win32.

Comment thread src/windows/process.rs
match signal {
Signal::Kill => unsafe { TerminateProcess(h, 1) }.map_err(|_| ()),
_ => Err(()),
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please find a way to wait for the process to be actually removed before returning.

@xoviat

xoviat commented Aug 17, 2026

Copy link
Copy Markdown
Author

I am going to close this for now, and I may come back to this later.

@xoviat xoviat closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants