Skip to content

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

Closed
@yuvalko

Description

@yuvalko

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()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions