您的位置:首页 > 编程语言 > Python开发

Python 打包程序判断是否已经运行

2015-05-12 17:13 453 查看
代码如下:

# -*- coding: UTF8 -*-
from win32com.client import Dispatch
import win32com
import sys, os
from PyQt4 import QtCore, QtGui

class Logicpy(QtGui.QWidget):
def __init__(self):
super(Logicpy, self).__init__()
self.resize(100, 100)
mythis = os.path.basename(os.path.realpath(sys.argv[0]))   # 获得当前文件的名字
exist = self.proc_exist(mythis)
if exist:
Ok = QtGui.QMessageBox.question(self, (u'提示'),(u'已经运行'), QtGui.QMessageBox.Yes)
if Ok == QtGui.QMessageBox.Yes:
exit()
# QtCore.QCoreApplication.quit()
# QtGui.qApp.quit  # 退出

#判断该进程是否存在
def proc_exist(self, process_name):
is_exist = False
wmi = win32com.client.GetObject('winmgmts:')
processCodeCov = wmi.ExecQuery('select * from Win32_Process where name=\"%s\"' %(process_name))
if len(processCodeCov) > 2:
is_exist = True
return is_exist

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
Logic = Logicpy()
Logic.show()
sys.exit(app.exec_())


效果:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐