The code is as follows:
1 #-*-Coding:utf8-*-2 fromWin32com.clientImportDispatch3 Importwin32com4 Importsys, OS5 fromPyQt4ImportQtcore, Qtgui6 7 classlogicpy (qtgui.qwidget):8 def __init__(self):9Super (logicpy, self).__init__()TenSelf.resize (100, 100) OneMythis = Os.path.basename (Os.path.realpath (sys.argv[0]))#get the name of the current file Aexist =self.proc_exist (mythis) - ifexist: -Ok = QtGui.QMessageBox.question (Self, (U'Tips'), (U'already running'), QtGui.QMessageBox.Yes) the ifOk = =QtGui.QMessageBox.Yes: - exit () - #QtCore.QCoreApplication.quit () - #QtGui.qApp.quit # Exit + - #determine if the process exists + defproc_exist (Self, process_name): AIs_exist =False atWMI = Win32com.client.GetObject ('winmgmts:') -Processcodecov = WMI. ExecQuery ('SELECT * from Win32_Process where name=\ "%s\"'%(process_name)) - ifLen (Processcodecov) > 2: -Is_exist =True - returnis_exist - in - to if __name__=="__main__": +App =qtgui.qapplication (SYS.ARGV) -Logic =logicpy () the logic.show () *Sys.exit (App.exec_ ())
Effect:
Python Packager Determines if it is already running