Skip to content

Instantly share code, notes, and snippets.

@0x2a94b5
Created July 23, 2020 04:55
Show Gist options
  • Select an option

  • Save 0x2a94b5/e82f6e3cd1041fca545dae0b598b7cc4 to your computer and use it in GitHub Desktop.

Select an option

Save 0x2a94b5/e82f6e3cd1041fca545dae0b598b7cc4 to your computer and use it in GitHub Desktop.

Revisions

  1. 0x2a94b5 created this gist Jul 23, 2020.
    29 changes: 29 additions & 0 deletions taskKill.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    #
    # Termainate an application on windows
    #

    from subprocess import run, CalledProcessError

    def taskCheck(name):
    cmd = "tasklist | findstr %s" % name
    try:
    run(cmd, shell=True, check=True)
    except CalledProcessError:
    return False
    return True

    def taskKill(name):
    cmd = "taskkill /F /IM %s /T > nul" % name
    try:
    run(cmd, shell=True, check=True)
    except CalledProcessError:
    return False
    return True

    if __name__ == '__main__':
    name = "edge.exe"
    if taskCheck(name):
    if taskKill(name):
    print("Successfully terminate %s." % name)