zoukankan      html  css  js  c++  java
  • Python 打包程序判断是否已经运行

    代码如下:

     1 # -*- coding: UTF8 -*-
     2 from win32com.client import Dispatch
     3 import win32com
     4 import sys, os
     5 from PyQt4 import QtCore, QtGui
     6 
     7 class Logicpy(QtGui.QWidget):
     8     def __init__(self):
     9         super(Logicpy, self).__init__()
    10         self.resize(100, 100)
    11         mythis = os.path.basename(os.path.realpath(sys.argv[0]))   # 获得当前文件的名字
    12         exist = self.proc_exist(mythis)
    13         if exist:
    14             Ok = QtGui.QMessageBox.question(self, (u'提示'),(u'已经运行'), QtGui.QMessageBox.Yes)
    15             if Ok == QtGui.QMessageBox.Yes:
    16                 exit()
    17                 # QtCore.QCoreApplication.quit()
    18                 # QtGui.qApp.quit  # 退出
    19 
    20     #判断该进程是否存在
    21     def proc_exist(self, process_name):
    22         is_exist = False
    23         wmi = win32com.client.GetObject('winmgmts:')
    24         processCodeCov = wmi.ExecQuery('select * from Win32_Process where name="%s"' %(process_name))
    25         if len(processCodeCov) > 2:
    26             is_exist = True
    27         return is_exist
    28 
    29 
    30 
    31 if __name__ == "__main__":
    32     app = QtGui.QApplication(sys.argv)
    33     Logic = Logicpy()
    34     Logic.show()
    35     sys.exit(app.exec_())

    效果:

  • 相关阅读:
    文本分类的研究学习
    Python中的TfidfVectorizer参数解析
    Newsgroups数据集介绍
    鸢尾花数据读取的总结
    Knapsack Problems
    3.1.6 Stamps
    3.1.5 Contact
    3.1.4 Shaping Regions
    3.1.3 Humble Numbers
    3.1.2 Score Inflation
  • 原文地址:https://www.cnblogs.com/dcb3688/p/4497960.html
Copyright © 2011-2022 走看看