python 判断一个进程是否存在
程序员文章站
2022-12-28 11:52:55
源代码如下:复制代码 代码如下:#-*- coding:utf-8 -*- def check_exsit(process_name): import win32com.c...
源代码如下:
#-*- coding:utf-8 -*-
def check_exsit(process_name):
import win32com.client
wmi = win32com.client.getobject('winmgmts:')
processcodecov = wmi.execquery('select * from win32_process where name="%s"' % process_name)
if len(processcodecov) > 0:
print '%s is exists' % process_name
else:
print '%s is not exists' % process_name
if __name__ == '__main__':
check_exsit('chrome.exe')
复制代码 代码如下:
#-*- coding:utf-8 -*-
def check_exsit(process_name):
import win32com.client
wmi = win32com.client.getobject('winmgmts:')
processcodecov = wmi.execquery('select * from win32_process where name="%s"' % process_name)
if len(processcodecov) > 0:
print '%s is exists' % process_name
else:
print '%s is not exists' % process_name
if __name__ == '__main__':
check_exsit('chrome.exe')