Skip to content

Instantly share code, notes, and snippets.

@0x2a94b5
Created July 23, 2020 04:55
Show Gist options
  • Save 0x2a94b5/e82f6e3cd1041fca545dae0b598b7cc4 to your computer and use it in GitHub Desktop.
Save 0x2a94b5/e82f6e3cd1041fca545dae0b598b7cc4 to your computer and use it in GitHub Desktop.
terminate an application
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment