Created
July 23, 2020 04:55
-
-
Save 0x2a94b5/e82f6e3cd1041fca545dae0b598b7cc4 to your computer and use it in GitHub Desktop.
terminate an application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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