Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Process.kill doesn't throw an exception on AccessDenied #1595

Closed
yuvalko opened this issue Sep 25, 2019 · 1 comment · May be fixed by payamn/follow_ahead_rl#2, emylincon/chatbot#1, SpriteLink/NIPAP#1275, imoisharma/helium#1 or matebestek/mldb#3

Comments

@yuvalko
Copy link

@yuvalko yuvalko commented Sep 25, 2019

Platform

  • { Windows 10 } windows
  • { 5.6.3 }

Bug description
When trying to kill a process and failing with "Access Denied" through the Process.kill method, psutil will not throw an exception if the returned handle doesn't have the requested permission.

The bug is in psutil_proc_kill in _psutil_windows.c. The current flow is:

  1. OpenProcess with PROCESS_TERMINATE
  2. TerminateProcess
  3. if TerminateProcess failed with access denied - do nothing.

Unfortunately, a valid handle can return from OpenProcess without the PROCESS_TERMINATE access right.
This might happen if the process is protected by windows or an anti-malware program.

This behavior was added to solve #1099.

Reproduce
On a computer with eset installed:

for process in psutil.process_iter():
    if process.name() == "eguiProxy.exe":
        print("killing")
        process.kill()
@yuvalko yuvalko added the bug label Sep 25, 2019
@yuvalko
Copy link
Author

@yuvalko yuvalko commented Sep 25, 2019

A valid solution might be checking if the process is alive after failing to kill it (Using WaitForSingleObject).
If the process is dead - do nothing.
Otherwise - throw an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment