import os
import win32process
import win32api as wapi
# exe文件位置和所在文件夹,
EXE_NAME = r"E:\Work\Test\test.exe"
EXE_DIR = r"E:\Work\Test"
# 加载进程 : 使用System来调用,可能会出错
r_v = os.system(EXE_NAME)
# 可以使用,但是关闭需要重新关闭
wapi.ShellExecute(0, 'open', EXE_NAME ,'',EXE_DIR ,1)
# 关闭:上面两种都可以使用
os.system('taskkill /F /IM %s' % EXE_NAME)
# 使用Win32Process.TerminateProcess函数--推荐,可配置更多
handle = win32process.CreateProcess(EXE_NAME , '', None, None, 0, win32process.CREATE_NO_WINDOW,
None, EXE_DIR , win32process.STARTUPINFO())
# win32process关闭
if handle != None:
win32process.TerminateProcess(handle[0], 0)