PowerToys/Plugins/Wox.Plugin.Kill/main.py

37 lines
841 B
Python
Raw Normal View History

2014-01-13 19:32:27 +08:00
#encoding=utf8
from __future__ import unicode_literals
import psutil
import json
def signalResult(process):
res = {}
res["Title"] = process.name
res["SubTitle"] = process.pid
res["ActionName"] = "killProcess"
res["IcoPath"] = "Images\\app.png"
res["ActionPara"] = process.pid
return res
def query(key):
name = key.split(" ")[1]
results = []
for i in psutil.get_process_list():
try:
if name:
if name.lower() in i.name.lower():
results.append(signalResult(i))
else:
results.append(signalResult(i))
except:
pass
return json.dumps(results)
2014-02-23 10:36:37 +08:00
def killProcess(context,pid):
2014-01-13 19:32:27 +08:00
p = psutil.Process(int(pid))
if p:
p.kill()
if __name__ == "__main__":
print killProcess(10008)