def Expired(): try: global_TB.status = 9 if global_TB.Expired_times == 0: if int(time.strftime("%Y%m%d")) > global_TB.ExpirationDate: print(global_TB.ExpirationDate) print(type(global_TB.ExpirationDate)) win32gui.MessageBox(0, '程序已经过期,请联系13299962008', '过期提示', win32con.MB_OK) #time.sleep(86400) try: print("why?????") #os._exit() #return #sys.exit() time.sleep(86400) print("wwwwwwww") except: Log("过期日" + str(global_TB.ExpirationDate)) elif global_TB.ExpirationDate - 12 < int( time.strftime("%Y%m%d")) < global_TB.ExpirationDate: win32gui.MessageBox(0, '程序即将过期,请联系13299962008', '警告', win32con.MB_OK) Log("即将过期,过期日:" + str(global_TB.ExpirationDate)) except Exception as e: Log(str(e)) global_TB.Expired_times = 1
def InvokeCommand(self, ci): print 'InvokeCommand' mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci # get the directory of our dll try: if hasattr(sys, "frozen"): # attempt to read the folder form registry first key = None try: key = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, 'Software\\ClamWin') currentDir = win32api.RegQueryValueEx(key, 'Path')[0] win32api.CloseHandle(key) except win32api.error: if key is not None: win32api.CloseHandle(key) # couldnt find it in the registry # get it from command line if sys.frozen == "dll": this_filename = win32api.GetModuleFileName( sys.frozendllhandle) else: this_filename = sys.executable currentDir = os.path.split(this_filename)[0] else: currentDir = os.path.split(os.path.abspath(__file__))[0] except NameError: # No __file__ attribute (in boa debugger) currentDir = os.path.split(os.path.abspath(sys.argv[0]))[0] os.chdir(currentDir) # we need to resort to calling external executable here # because wxPython has some threading issues when called from # multiple Windows Explorer instances # read this value from registry exe = os.path.join(currentDir, 'Blindata.exe') if not os.path.exists(exe): win32gui.MessageBox(hwnd, 'Could not locate file: %s' % exe, 'ClamWin', win32con.MB_OK | win32con.MB_ICONEXCLAMATION) else: cmd = '"%s" --mode=scanner --path="%s"' % (exe, self._fname) try: proc = Process.ProcessOpen(cmd) proc.close() except Process.ProcessError: win32gui.MessageBox( hwnd, 'Could not execute %s.' % cmd, 'ClamWin', win32con.MB_OK | win32con.MB_ICONEXCLAMATION)
def app_error(error_type, error_str, wParent): if NATIVE_WSET == 'Windows': import win32gui if error_type == E_FATAL: win32gui.MessageBox(wParent, error_str, "Error", FLAGS_FATAL) exit(E_FATAL) elif error_type == E_WARN: win32gui.MessageBox(wParent, error_str, "Error", FLAGS_WARN) else: if error_type == E_FATAL: g_msg_dialog(wParent, error_str) exit(E_FATAL) elif error_type == E_WARN: g_msg_dialog(wParent, error_str)
def main(): global bot, tray def discord_thread(): bot.run(TOKEN) bot = TempBot(activity=discord.Activity( name='!temp help', type=discord.ActivityType.listening)) threading.Thread(target=discord_thread, name='DiscordThread').start() tray_menu = ['menu', ['Exit']] tray = sg.SystemTray(menu=tray_menu, data_base64=ICON, tooltip=NAME) try: if HardwareInfo().failed_to_load: win32gui.MessageBox( None, 'Open Hardware Monitor must be running for !temp to work.', 'Warning', 48) except: traceback.print_exc() bot.loop.create_task(bot.notify_startup_crash()) while True: # Handle Tray events event = tray.Read() if event == 'Exit': tray.Hide() bot.loop.create_task(bot.temp_wait_before_exit(close=True)) break
def choose(self, wid): self.logger.info('choose: wid=%r' % wid) if wid == self.IDI_QUIT: self.close() elif wid == 123: win32gui.MessageBox(self._hwnd, u'testing', u'foo', win32con.MB_OK) return
def attack(self): if self.AttackTxt.get() == "Attack": try: print(self.typeAttack.get()) requests.get(self.urlAttack.get()) if(self.server.getOnlineBots()>0): self.server.attack(self.urlAttack.get(), "$"+self.typeAttack.get()) self.AttackTxt.set("Stop") else: win32gui.MessageBox(None, "The application can not run an attack with 0 bots online.", "Warning!",(win32con.MB_ICONWARNING | win32con.MB_OK)) except Exception as e: win32gui.MessageBox(None, str(e), "Error!", (win32con.MB_ICONERROR | win32con.MB_OK)) else: self.server.stopattack() self.AttackTxt.set("Attack")
def _UpdateDB(self, schedule_label): if not schedule_label: try: params = (' --mode=update', ' --config_file="%s"' % self._config.GetFilename(),) Utils.SpawnPyOrExe(False, os.path.join(Utils.GetCurrentDir(True), 'ClamWin'), *params) except Exception, e: win32gui.MessageBox(self.hwnd, 'An error occured while starting ClamWin Free Antivirus Update.\n' + str(e), 'ClamWin Free Antivirus', win32con.MB_OK | win32con.MB_ICONERROR)
def ApplyHandlingOptionValueError(self, func, *args): try: return func(*args) except ValueError, why: mb_flags = win32con.MB_ICONEXCLAMATION | win32con.MB_OK win32gui.MessageBox(self.hwnd, str(why), "SpamBayes", mb_flags) return False
def MsgAlert(sMessage, sTitle, flags=Icon.BLANK + Button.OK, beep=False): ''' flags are combinations of the following hex numbers, aliased as indicated: Buttons Style: ButtonOk : 0 : OK ButtonOkCancel : 1 : OK, Cancel ButtonAbortRetryIgnore : 2 : Abort, Retry, Ignore ButtonYesNoCancel : 3 : Yes, No, Cancel ButtonYesNo : 4 : Yes, No ButtonRetryCancel : 5 : Retry, Cancel ButtonCancelAgainContinue : 6 : Cancel, Try Again, Continue ButtonCancelAgainContinueTB : 7 : Cancel, Try Again, Continue In Taskbar BeepNoMessageBox : 8 : Beeps, but no MessageBox DontKnow : 9 : Beeps, but no MessageBox Icon Style: IconNone : 0 : (blank) IconX : 16 : X IconQMark : 32 : ? IconBang : 48 : ! IconI : 64 : i IconBlank : 80 : (blank) ''' response = win32gui.MessageBox(0, sMessage, sTitle, flags) if beep: win32gui.MessageBeep(0) return response
def _ShowLog(self, logfile): try: curDir = Utils.GetCurrentDir(True) params = (' --mode=viewlog', '--path="%s"' % logfile) Utils.SpawnPyOrExe(False, os.path.join(curDir, 'ClamWin'), *params) except Exception, e: win32gui.MessageBox(self.hwnd, 'An error occured while displaying log file %s.\nError: %s' % (logfile, str(e)), 'ClamWin Free Antivirus', win32con.MB_OK | win32con.MB_ICONERROR)
def btnExcute_click(self, sendor, sType, wParam, lParam): def PyThreadPythonExecute(): try: self._StartAnimation() self._ExecutePython() except Exception as e: PyLog().LogText(str(traceback.format_exc())) self._StopAnimation() PyLog().LogText('PyThreadExecute exit') # 多线程测试 t = threading.Thread(target=PyThreadPythonExecute) t.start() # ctypes测试 windll.user32.MessageBoxW(0, "中文", "Your title", win32con.MB_YESNO) windll.user32.MessageBoxA(0, "中文".encode('gbk'), "Your title".encode('gbk'), win32con.MB_YESNO) # win32gui测试 import win32gui win32gui.MessageBox(self.GetHWnd(), '中文', 'Your title', win32con.MB_YESNO | win32con.MB_ICONINFORMATION | win32con.MB_SYSTEMMODAL) (a, b, c) = win32gui.GetOpenFileNameW() print(a, b, c) win32gui.MessageBox(self.GetHWnd(), a, str(b), win32con.MB_YESNO | win32con.MB_ICONINFORMATION | win32con.MB_SYSTEMMODAL) # 进程间消息测试 hwnd = windll.user32.FindWindowW(None, '计算器') if windll.user32.IsWindow(hwnd): msgstr = '计算器' + '\0' print(len(msgstr)) msgbytes = msgstr.encode('utf-8') copydata = COPYDATASTRUCT(None, len(msgbytes), msgbytes) for i in range(1, 2): # time.sleep(1) PyLog().LogText('%d'%i) windll.user32.SendMessageA(hwnd, 0x4a, None, byref(copydata))
def _ShowClamWin(self, path=''): try: if path: params = (' --mode=scanner', ' --path=\"%s\"' % path) else: params = (' --mode=main',) Utils.SpawnPyOrExe(False, os.path.join(Utils.GetCurrentDir(True), 'ClamWin'), *params) except Exception, e: win32gui.MessageBox(self.hwnd, 'An error occured while starting ClamWin Free Antivirus scanner.\n' + str(e), 'ClamWin Free Antivirus', win32con.MB_OK | win32con.MB_ICONERROR)
def _OpenWebPage(self, url): try: import webbrowser webbrowser.open(url) except ImportError: win32gui.MessageBox(self.hwnd, 'Please point your browser at: %s' % url, 'Blindata Antivirus', win32con.MB_OK | win32con.MB_ICONINFORMATION)
def CopyCallBack(self, hwnd, func, flags, srcName, srcAttr, destName, destAttr): # This function should return: # IDYES Allows the operation. # IDNO Prevents the operation on this folder but continues with any other operations that have been approved (for example, a batch copy operation). # IDCANCEL Prevents the current operation and cancels any pending operations. print("CopyCallBack", hwnd, func, flags, srcName, srcAttr, destName, destAttr) return win32gui.MessageBox(hwnd, "Allow operation?", "CopyHook", win32con.MB_YESNO)
def HelpAbout(): try: curDir = Utils.GetCurrentDir(True) Utils.SpawnPyOrExe(True, os.path.join(curDir, 'ClamWin'), ' --mode=about') except Exception, e: win32gui.MessageBox( GetWindow(), 'An error occured in ClamWin Free Antivirus About Box.\n' + str(e), 'ClamWin Free Antivirus', win32con.MB_OK | win32con.MB_ICONERROR)
def con(): total = 0 conver = 0 failed = [] pathin = fr"{l1()}".replace("/", "\\") pathout = fr"{l2()}".replace("/", "\\") win32gui.MessageBox(0, f"Converting from {pathin} to {pathout}", "Doc2Pdf", 0) word = win32com.client.Dispatch('Word.Application') for dirpath, dirnames, filenames in os.walk(pathin): for f in filenames: try: if f.lower().endswith(".docx"): new_name = f.replace(".docx", ".pdf") in_file = (dirpath + '/' + f) new_file = (pathout + '/' + new_name) doc = word.Documents.Open(in_file) doc.SaveAs(new_file, FileFormat=17) doc.Close() conver += 1 if f.lower().endswith(".doc"): new_name = f.replace(".doc", ".pdf") in_file = (dirpath + '/' + f) new_file = (pathout + '/' + new_name) doc = word.Documents.Open(in_file) doc.SaveAs(new_file, FileFormat=17) doc.Close() conver += 1 except: failed.append(f) total += 1 word.Quit() win32gui.MessageBox(0, f"{conver} files converted out of {total}", "Doc2Pdf", 0) if conver != total: win32gui.MessageBox(0, f"There was an access problem in: {failed}", "Doc2Pdf", 0)
def stop_0(ch='1'): # ch = 'a' break0 = 0 ch = ch.upper() if (dm.GetKeyState(ord(ch))): print('------- Stop! --------') break0 = ( win32gui.MessageBox(0, 'Do you continue?', 'Stop!', 1) - 1) if (break0 == 1): print('------ Break!!! ---------') # return break0 return break0
def _ShowConfigure(self, switchToSchedule = False): try: curDir = Utils.GetCurrentDir(True) if switchToSchedule: mode = 'configure_schedule' else: mode = 'configure' params = (' --mode=%s' % mode, ' --config_file="%s"' % self._config.GetFilename(),) Utils.SpawnPyOrExe(False, os.path.join(curDir, 'ClamWin'), *params) except Exception, e: win32gui.MessageBox(self.hwnd, 'An error occured while starting ClamWin Free Antivirus Preferences.\n' + str(e), 'ClamWin Free Antivirus', win32con.MB_OK | win32con.MB_ICONERROR)
def instance_running(self): ''' Use CreateEvent to make sure there is only one instance running ''' if self.SICHECK_EVENT is None: self.SICHECK_EVENT = win32event.CreateEvent(None, 1, 0, self.GUID) # An instance is already running, quit if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS: win32gui.MessageBox( self.HWND, 'You can only run one instance at a time', 'Seems like KeyCounter is already running', win32con.MB_OK) return self.stop()
def alert(title, msg): if getattr(sys, 'frozen', None): if platform.system() == "Darwin": import Tkinter, tkMessageBox root = Tkinter.Tk() root.lift() root.attributes('-topmost', 1) root.withdraw() tkMessageBox.showinfo(title, msg) elif platform.system() == "Windows": import win32gui win32gui.MessageBox(0, msg, title, 0)
def OnOpen(self, cancel): dbg_print('MailItemWithEvents:OnOpen') if not self._scanned and self.Sent: # in case OnRead has not been called dbg_print('MailItemWithEvents:OnOpen scanning') self._scanned = True self._num_infected = ScanMailItem(self, False) elif self._num_infected: # a bit of trickery here - remove and reinsert attachments # so that bloody outlook shows our changes dbg_print('MailItemWithEvents:OnOpen Scanned Earlier') try: saved_attachments = [] for i in range(self.Attachments.Count - self._num_infected + 1, self.Attachments.Count + 1): att = self.Attachments.Item(i) # save attachment to a temp file name = att.DisplayName dir = tempfile.mktemp() os.mkdir(dir) filename = os.path.join(dir, name) att.SaveAsFile(filename) saved_attachments.append((att, filename)) for saved in saved_attachments: saved[0].Delete() for saved in saved_attachments: self.Attachments.Add(Source=saved[1], Type=constants.olByValue) for saved in saved_attachments: safe_remove(saved[1], True) saved_attachments = [] try: self.Save() except pythoncom.com_error, e: # read only message store (hotmail, etc # ignore save errors hr, desc, exc, argErr = e if hr != -2147352567: raise e except Exception, e: for saved in saved_attachments: safe_remove(saved[1], True) msg = 'ClamWin Free Antivirus could not replace an attachment. Error: %s' % str( e) win32gui.MessageBox(GetWindow(), msg, 'ClamWin Free Antivirus!', win32con.MB_ICONERROR | win32con.MB_OK)
def _StopProcesses(self): # check if process is still running for proc in self._processes: if self._IsProcessRunning(proc): # running - kill proc.kill() #wait to finish if self._IsProcessRunning(proc, True): #still running - complain and terminate win32gui.MessageBox(self.hwnd, 'Unable to stop scheduled process, terminating', 'ClamWin Free Antivirus', win32con.MB_OK | win32con.MB_ICONSTOP) os._exit(0) proc.close() self._processes = []
def main(debug, cookie): while True: ## log_file = open(r"C:\learn\py\我关注的UP的粉丝数\debug.log", "w") try: print("start") write_log("start") dicts = get_dicts(debug, cookie) # 把数据变成[mid, uname] data = lDict2lData(dicts) # 把处理过的数据变成{mid: [uname, 粉丝数, timestamp]} result = dFollower(data, cookie) # 打印结果 ## pprint(result) with open(r".\record.pkl", "rb+") as f: try: before = pickle.load(f) except EOFError: print("Can't read the file.") before = [] write_obj = before + [result] f.seek(0) pickle.dump(write_obj, f) print("Done.") write_log("Done.") for i in range(600): time.sleep(1) except Exception: err = traceback.format_exc() print("There's something wrong:", err) write_log("There's something wrong:" + err) result = win32gui.MessageBox( 0, err + "\r" + "想要终止程序吗?", "Error", win32con.MB_YESNO | win32con.MB_ICONWARNING) if result == 6: quit() time.sleep(60) continue except KeyboardInterrupt: quit()
def OnCommand(self, hwnd, msg, wparam, lparam): if self._nomenu: return id = win32api.LOWORD(wparam) if id == self.MENU_OPEN_CLAM: self._ShowClamWin() elif id == self.MENU_UPDATE_DB: self._UpdateDB(lparam) elif id == self.MENU_CHECK_UPDATE: self._OpenWebPage( 'http://www.blindata.com/index.php?option=content&task=view&id=40&Itemid=60&version=' + version.clamwin_version) elif id == self.MENU_CLAMWIN_WEB: self._OpenWebPage('http://www.blindata.com') elif id == self.MENU_CONFIGURE: self._ShowConfigure() elif id == self.MENU_SHOWSCANLOG: self._ShowLog(self._config.Get('ClamAV', 'LogFile')) elif id == self.MENU_SHOWUPDATELOG: self._ShowLog(self._config.Get('Updates', 'DBUpdateLogFile')) elif id == self.MENU_EXIT: self.OnExit() elif id == self.MENU_CONFIGURESCHEDULER: self._ShowConfigure(True) elif id == self.MENU_TERMINATESCHEDULE: self._TerminateSchedules() self._InitSchedulers() elif (id >= self.MENU_RUNSCHEDULE) and \ (id < self.MENU_RUNSCHEDULE + len(self._scheduledScans)): try: path = self._scheduledScans[id - self.MENU_RUNSCHEDULE].Path if path[len(path) - 1] == '\\': path = path[:len(path) - 1] self._ShowClamWin(path) except Exception, e: win32gui.MessageBox( self.hwnd, 'Could not launch Blindata Scanner. Error: %s' % str(e), 'Blindata Free Antivirus', win32con.MB_OK | win32con.MB_ICONERROR)
def Activate(self, AddInSiteObject, firstTime): """ :param AddInSiteObject: Inventor.ApplicationAddInSite :param firstTime: bool :return: Void the Activate method is called by Inventor when it loads the addin the AddInSiteObject provides access to the Inventor Application object the FirstTime flag indicates if the addin is loaded for the first time """ try: addIn_app = AddIn(AddInSiteObject) if firstTime: addIn_app.create_ui() # win32gui.MessageBox(None, u"LOAD OK", u"OK", 0) except Exception as err: win32gui.MessageBox( None, u"Error while loading Python.InventorAddIn %s" % err, u"ERROR", 0)
def InitMenu(hwnd): try: #初始化菜单 f = open(GetParentPath("\\menu\\menus_map.json"), "r") s = f.read() j = json.loads(s) if (getAppCfg("is_show_menu") == "0"): return global menuData menuData = j["menus"] menus = win32gui.CreateMenu() for d in menuData: #print d["id"] #print d["title"] win32gui.AppendMenu(menus, win32con.MF_STRING | win32con.MF_ENABLED, int(d["id"]), d["title"]) win32gui.SetMenu(hwnd, menus) except: win32gui.MessageBox(None, u"初始化菜单失败", u"错误", 0)
def InvokeCommand(self, ci): mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci win32gui.MessageBox(hwnd, "Hello", "Wow", win32con.MB_OK)
def msgBox(hwnd=None, text='提示信息', caption='窗口标题'): win32gui.MessageBox(hwnd, text, caption, win32con.MB_OK) print(1111111)
def alertMessage(msg, text = '', style = win32con.MB_ICONINFORMATION): return win32gui.MessageBox(None, msg, text, style|win32con.MB_SYSTEMMODAL)
def msgbox(text, caption='Error'): win32gui.MessageBox(None, text, caption, (win32con.MB_OK | win32con.MB_ICONERROR)) return