Skip to main content

Kill procs

Project description

Multikill

pip install killallappsinfolder

Tested against Windows 10 / Python 3.11 / Anaconda

ProcKiller

ProcKiller is a Python utility designed to identify and terminate processes running on a Windows machine based on specific executable files found within given directories. It utilizes the Windows API through the ctypes library to manage processes.

Features

  • Executable Filtering: Search for executable files within specified directories.
  • Process Mapping: Map running processes to executables.
  • Process Termination: Terminate processes based on matching executable files.
  • Customizable Termination Criteria: Include options for sending different signals and handling child processes.

Usage

To use ProcKiller, run the script from the command line with directories as arguments, followed by the interval (in seconds) for repeated execution. Here’s how to invoke it:

python prockiller.py "C:\path\to\first\directory" "C:\path\to\second\directory" 60

This will search for executables in the specified directories and terminate any matching running processes every 60 seconds.

Components

Main Functions

  • get_command_line(pid): Retrieves the command line used to start a process.
  • get_all_executables(folder, exeendings, filter_function): Searches for executable files in a specified folder.
  • get_procs_to_kill(allexefiles_onlyexe, allfullpath): Identifies running processes that should be terminated.
  • kill_running_procs(allprocsdic, ...): Terminates the processes identified for termination.

Class Definition

  • ProcKiller: A class to encapsulate the functionality of finding and killing processes.

Command-Line Interface

  • The script can be executed directly from the command line with specified parameters for directories and execution interval.

Code Example

pki = (
ProcKiller(
    folders=(
        r"C:\ProgramData\BlueStacks_nxt",
        r"C:\Program Files\Oracle",
        r"C:\Program Files\BlueStacks",
        r"C:\Program Files\BlueStacks_nxt",
    ),
    kill_timeout=2,
    protect_myself=True,  # important, protect_myselfis False, you might kill the whole python process you are in.
    winkill_sigint_dll=True,  # dll first
    winkill_sigbreak_dll=True,
    winkill_sigint=True,  # exe from outside
    winkill_sigbreak=True,
    powershell_sigint=True,
    powershell_sigbreak=True,
    powershell_close=True,
    multi_children_kill=False,  # try to kill each child one by one
    multi_children_always_ignore_pids=(0, 4),  # ignore system processes
    print_output=True,
    taskkill_as_last_option=True,  # this always works, but it is not gracefully anymore):
    exeendings=(".com", ".exe"),
    filter_function=lambda files: True,
)
.get_active_procs()
.kill_running_procs()
)
# Use it again to keep on killing
pki()

Contributions

Contributions are welcome! If you find a bug or have suggestions for improvements, please open an issue or submit a pull request.

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

killallappsinfolder-0.10.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

killallappsinfolder-0.10-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file killallappsinfolder-0.10.tar.gz.

File metadata

  • Download URL: killallappsinfolder-0.10.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for killallappsinfolder-0.10.tar.gz
Algorithm Hash digest
SHA256 6dd699c5d12b0e4a64f54b3ebb1aa45c9a55279eeaf21dd0fcab6dad721107d1
MD5 35cc1ffeb1cd412a74ebe504b04a37d8
BLAKE2b-256 14e5364fffe1c93b888cf85efbef8d4f3ca1d748fc9da96b7b03eaffba069b05

See more details on using hashes here.

File details

Details for the file killallappsinfolder-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for killallappsinfolder-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 82e00bcd245608855531f40516d67701db73a9fa0459d82c03008be9380581c8
MD5 a3299234ad9318459073d40dd90aead4
BLAKE2b-256 503e55371f0be0cef11aee9761de7bb085737004f5c5ce1b2b3ddf8a9206f528

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page