def on_flightButton_clicked(self): # 项目打开成功了,然后打开主面板 mainWindow = MainWindow("flightButton", None) mainWindow.start() sleep(5) # 打开控制界面的槽函数 if path.isfile(self.RhapsodyProjectExePath): if '.exe' in self.RhapsodyProjectExePath: ShellExecute(0, 'open', self.RhapsodyProjectExePath, "", '', 1) # print("打开rhapsody成功!!!") else: curPath = QDir.currentPath() dlgTitle = u"打开Rhapsody项目编译之后可执行文件" filt = u"执行程序(*.exe);;所有文件(*.*)" filename, _ = QFileDialog.getOpenFileName(self, dlgTitle, curPath, filt) if ".exe" in filename.lower(): ShellExecute(0, 'open', filename, "", '', 1) elif filename == '': pass else: dlgTitle = u"打开错误" strInfo = u"打开Rhapsody项目编译之后可执行文件" QMessageBox.critical(self, dlgTitle, strInfo)
def on_pycharmButton_clicked(self): # 该函数为打开pycharm按键的槽函数,即按下按键会执行该函数 u""" #判断文件是否存在,若存在则再判断,路径是否正确,方法判断路径里面是否含有"pycharm",该方法不严谨,但基本够用, 若无误则使用win32api.ShellExecute()函数打开 若不存在则调用打开文件窗口,选择程序打开,若选择的不是指定软件,则弹出警告窗口。需要重新选择 以下三个按键都一个逻辑 """ if path.isfile(self.pycharmPath) and path.isdir(self.pyProjectPath): if "pycharm" in self.pycharmPath.lower(): ShellExecute(0, 'open', self.pycharmPath, self.pyProjectPath, '', 1) # 其中前两个为固定,第三个为打开软件的路径, # 第四个是使用该软件打开该文件(或文件夹) # 若没有则放空字符 '' # print("打开PyCharm成功!!!") else: curPath = QDir.currentPath() dlgTitle = u"打开PyCharm软件" filt = u"执行程序(*.exe);;所有文件(*.*)" filename, _ = QFileDialog.getOpenFileName(self, dlgTitle, curPath, filt) if "pycharm" in filename.lower(): ShellExecute(0, 'open', filename, '', '', 1) elif filename == '': pass else: dlgTitle = u"打开错误" strInfo = u"请打开PyCharm程序" QMessageBox.critical(self, dlgTitle, strInfo)
def driver_initial(): """ 初始化浏览器对象并序列化 :return: """ client_socket = socket.socket(AF_INET, SOCK_STREAM) try: # setdefaulttimeout(1) 导致启动浏览器异常 设为较大时间 如 10 无异常 client_socket.settimeout(2) client_socket.connect(('127.0.0.1', 4444)) client_socket.close() print('4444端口已占用,geckodriver已启动') return True except Exception as e: print('Error :', e) print('4444端口未占用,geckodriver未启动') ShellExecute(0, 'open', 'geckodriver', '', '', 1) # ShellExecute(hwnd, op, file, params, dir, bShow) # 其参数含义如下所示。 # hwnd:父窗口的句柄,如果没有父窗口,则为0。 # op:要进行的操作,为“open”、“print”或者为空。 # file:要运行的程序,或者打开的脚本。 # params:要向程序传递的参数,如果打开的为文件,则为空。 # dir:程序初始化的目录。 # bShow:是否显示窗口。 # firefox.exe -ProfileManager -no-remote driver = webdriver.remote.webdriver.WebDriver( command_executor="http://127.0.0.1:4444", browser_profile=FirefoxProfile(FIREFOX_DIR), desired_capabilities=DesiredCapabilities.FIREFOX) # driver.get('about:blank') put_browser(driver) return False
def OK_buttonClick(self): settings = [ self.spinBox_1.value() if self.checkBox_1.isChecked() else 0, self.spinBox_2.value() if self.checkBox_2.isChecked() else 0, self.spinBox_3.value() if self.checkBox_3.isChecked() else 0, self.spinBox_4.value(), ] settings = [str(s) for s in settings] # generate link in startup directory = path.dirname(sys.argv[0]) target = path.join(directory, "BingWallpaper.exe") arguments = ' '.join(settings) winshell.CreateShortcut( Path=path.join(winshell.startup(), "BingWallpaper.lnk"), Target=target, Arguments=arguments, StartIn=directory, ) # messagebox question, ask to download ans = QMessageBox.question(self, "创建配置", "成功配置开机启动!\n是否立即执行程序?", QMessageBox.Ok | QMessageBox.Cancel) if ans == QMessageBox.Ok: ShellExecute(0, 'open', target, arguments, directory, 1) self.close()
def Execute(self, exe, path): try: res = ShellExecute(0, None, exe, None, path, 1) except: res = None self.PrintError(self.text.text2 % exe) return res
def __call__(self): try: ShellExecute(0, None, "MTStart.exe", self.value, self.plugin.myTheatrePath, 0) return True except: raise self.Exceptions.ProgramNotFound
def startServer(self): with open('./NodejsWebApp1/server.js', 'r', encoding='utf8') as f: file = f.readlines() file[0] = "port = " + str(self.port) + ";\n" for i in range(len(file)): if "startTimer(" in file[i] and "function" not in file[i]: file[i] = "\t\tstartTimer(" + str(self.timer) + ");\n" break # file[243] = "\t\tstartTimer(" + str(self.timer) +");\n" # TODO with open('./NodejsWebApp1/server.js', 'w', encoding='utf8') as f: f.writelines(file) if "1" in (subprocess.check_output('sc query "mongodb"').decode( 'utf-8').split('\r\n')[3]): ShellExecute(lpVerb='runas', lpFile='cmd.exe', lpParameters='/c ' + "sc start MongoDB") command = 'node ./NodejsWebApp1/server.js' # /NodejsWebApp1 #self.p.communicate(command) self.p = subprocess.Popen(command, shell=True) webbrowser.register('chrome', Chrome('chrome')) webbrowser.open('http://localhost:' + str(self.port) + '/admin') self.setWindowTitle("伺服器已啟動:port=" + str(self.port) + ", 作答時間: " + str(self.timer) + "秒")
def elevate(argv=None, cwd=None, use_arguments=True, show=True): """Run a subprocess with elevated privileges. (Should work with both UAC and Guest accounts) @param argv: Command to run. C{None} for self. @param cwd: Working directory or C{None} for C{os.getcwd()} @param use_arguments: If False, PyWin32 is not required. @param show: See bShow in C{win32api.ShellExecute} docs. (Ignored if use_arguments = C{False}) @note: This assumes that sys.argv[0] is absolute or relative to cwd. @todo: Get access to something newer than XP to test on. """ argv = argv or sys.argv cwd = cwd or os.getcwd() if isinstance(argv, basestring): argv = [argv] cmd = os.path.normpath(argv[0]) if use_arguments: from win32api import ShellExecute from subprocess import list2cmdline args = list2cmdline(argv[1:]) ShellExecute(0, 'runas', cmd, args, cwd, show) else: os.chdir(cwd) os.startfile(os.path.normpath(cmd), 'runas')
def execute(self, msg, unit, address, when, printer, print_copies): filename = mktemp('.txt') open(filename, 'w').write("""\ Got a page! Unit: %(unit)s Address: %(address)s When: %(when)s %(msg)s """ % dict(msg=msg, unit=unit, address=address, when=when.ctime())) if printer is None: action = 'print' else: action = 'printto' printer = '"%s"' % printer for x in range(print_copies): ShellExecute( 0, action, filename, printer, '.', 0 )
def execute(self, msg, unit, address, when, printer, print_copies): url = 'http://maps.googleapis.com/maps/api/directions/json?%s' % urlencode(( ('origin', self.home), ('destination', address) )) ur = urllib.urlopen(url) result = json.load(ur) filename = mktemp('.txt') with open(filename, 'w') as output: for i in range(0, len(result['routes'][0]['legs'][0]['steps'])): s = (result['routes'][0]['legs'][0]['steps'][i]['html_instructions']) d = (result['routes'][0]['legs'][0]['steps'][i]['distance']['text']) l = (result['routes'][0]['legs'][0]['steps'][i]['duration']['text']) s = re.sub('<[A-Za-z\/][^>]*>', '', s) output.writelines(s + " " + d + " " + l + '\n') if printer is None: action = 'print' else: action = 'printto' printer = '"%s"' % printer for x in range(print_copies): ShellExecute( 0, action, filename, printer, '.', 0 )
def on_release(key): ' 释放检测 ' if (key == Otherkey.NONE_KEY): ShellExecute( 0, 'open', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', '', '', 1)
def __call__(self, cmdLineArgs=""): vlcPath = GetVlcPath() return ShellExecute( 0, None, vlcPath, self.GetCmdLineArgs(cmdLineArgs), None, #os.path.dirname(vlcPath), 1)
def on_matlabButton_clicked(self): if path.isfile(self.matlabPath): if "matlab" in self.matlabPath.lower(): ShellExecute(0, 'open', self.matlabPath, '', '', 1) else: curPath = QDir.currentPath() dlgTitle = u"打开MatLab软件" filt = u"执行程序(*.exe);;所有文件(*.*)" filename, _ = QFileDialog.getOpenFileName(self, dlgTitle, curPath, filt) if "matlab" in filename.lower(): ShellExecute(0, 'open', filename, '', '', 1) elif filename == '': pass else: dlgTitle = u"打开错误" strInfo = u"请打开MatLab程序" QMessageBox.critical(self, dlgTitle, strInfo)
def start_genshin(): try: # ShellExecute(0, 'open', address + "Genshin Impact Game/YuanShen.exe", '', '', 1) ShellExecute(0, 'open', "C:/Users/AMD PC/Desktop/genshin.bat", '', '', 1) with open(address + "travel.txt", 'w') as f: f.write("False\n") except BaseException: with open(address + "travel.txt", 'a') as f: f.write('True')
def __call__(self): if self.plugin.useRunCmdPlugin: command = self.value[1] else: command = self.value[0] # This one is quite simple. It just calls ShellExecute. try: head, tail = os.path.split(self.plugin.foobar2000Path) return ShellExecute(0, None, tail, command, head, 1) except: # Some error-checking is always fine. raise self.Exceptions.ProgramNotFound
def Execute(self, exe, path, param = None): try: ShellExecute( 0, None, exe, param, path, 1 ) except: self.PrintError(self.text.text2 % exe)
def begin_program(self): config = ConfigParser() config.read("projectPath.ini", encoding='utf-8') RhapsodyProjectExePath = config['DEFAULT']["RhapsodyProjectExePath"] if path.isfile(RhapsodyProjectExePath): if '.exe' in RhapsodyProjectExePath: ShellExecute(0, 'open', RhapsodyProjectExePath, "", '', 1) # print("打开rhapsody成功!!!") else: curPath = QDir.currentPath() dlgTitle = u"打开Rhapsody项目编译之后可执行文件" filt = u"执行程序(*.exe);;所有文件(*.*)" filename, _ = QFileDialog.getOpenFileName(self, dlgTitle, curPath, filt) if ".exe" in filename.lower(): ShellExecute(0, 'open', filename, "", '', 1) elif filename == '': pass else: dlgTitle = u"打开错误" strInfo = u"打开Rhapsody项目编译之后可执行文件" QMessageBox.critical(self, dlgTitle, strInfo)
def ensure_device_launched(self): self.logger.debug("triggering emulator to start...") if self._is_device_online(): self.logger.debug("emulator has already been launched") else: self._kill_all_device_processes() self._wait(2) ShellExecute(0, 'open', config.get('device/emulator_launcher'), '', '', 1) for _ in range(30): if self._is_device_online(): break self._wait(1, manlike=False) else: raise TimeoutError('time out launching emulator') self.logger.debug("emulator has launched")
def newVersion(a): ShellExecute(0, "open", "https://pan.baidu.com/s/1nxl6QuP", "", "", 1)
# Vista and later, run as administrator, so elevated mode: openpar = "runas" else: openpar = "open" pathToPythonW = os.path.join(sys.prefix, "pythonw.exe") if not os.path.isfile(pathToPythonW): print("cannot find the Pythonw exectutable: %s" % pathToPythonW) # time.sleep(30) sys.exit() configPath = os.path.join(os.path.dirname(__file__), "configurenatlink.pyw") if not os.path.isfile(configPath): print( "cannot find the Natlink/Unimacro/Vocola configuration program: %s" % configPath) # time.sleep(30) sys.exit() #print('run with "%s": %s'% (openpar, configPath) #print('sys.version: ', sys.version #time.sleep(5) ShellExecute(0, openpar, pathToPythonW, configPath, "", 1) import traceback traceback.print_exc() except: import traceback traceback.print_exc() time.sleep(60)
from win32api import ShellExecute, GetVersionEx # see natlinkstatus.py for windows versions (getWindowsVersion) wversion = GetVersionEx() if wversion[3] == 2 and wversion[0] >= 6: # Vista and later openpar = "runas" else: openpar = "open" pathToPython = os.path.join(sys.prefix, "python.exe") if not os.path.isfile(pathToPython): print "cannot find the python executable: %s"% pathToPython while True: pass raise configFunctionsPath = os.path.join(os.path.dirname(__file__), "natlinkconfigfunctions.py") if not os.path.isfile(configFunctionsPath): print "cannot find the CLI configuration program: %s"% configFunctionsPath while True: pass raise print 'run with "%s": %s'% (openpar, configFunctionsPath) ShellExecute(0, openpar, pathToPython, configFunctionsPath, "", 1)
# coding=utf-8 from core.bot import Bot from win32api import ShellExecute import os import time if __name__ == "__main__": mcl_path = os.path.abspath( os.path.dirname(os.path.abspath(__file__)) + os.path.sep + ".." + os.path.sep + ".." + os.path.sep + "mcl.cmd" ) ShellExecute(0, "open", mcl_path, "", "", 1) time.sleep(7) Bot().start()
import webbrowser from win32api import ShellExecute webbrowser.get('windows-default').open_new( "https://hackmd.io/@immortalmice/Hkj9s-CvU/https%3A%2F%2Fhackmd.io%2Fdz9INck7Qhyk5HJGS-oTDg" ) ShellExecute(0, "open", "C:\\Users\\IceIc\\eclipse\\java-2020-06\\eclipse\\eclipse.exe", "", "", 0)
def cmd_exe(event=None): path = tempfile.gettempdir() motor_model = string.upper(e.get()) main_function(motor_model) Tk.quit ShellExecute(0,'open',r'{}\result.html'.format(path),'','',1)
def on_mainSystemButton_clicked(self): # 打开主面板 # 打开rhapsody软件 if path.isfile(self.RhapsodyPath) and path.isfile( self.RhapsodyProjectPath): if "rhapsody" in self.RhapsodyPath.lower( ) and '.rpy' in self.RhapsodyProjectPath: # win32api.ShellExecute(0, 'open', self.RhapsodyPath, self.RhapsodyProjectPath, '', 1) Rhapsody = Popen([self.RhapsodyPath, self.RhapsodyProjectPath]) print(Rhapsody) # print("打开rhapsody成功!!!") else: curPath = QDir.currentPath() dlgTitle = u"打开Rhapsody软件" filt = u"执行程序(*.exe);;所有文件(*.*)" filename, _ = QFileDialog.getOpenFileName(self, dlgTitle, curPath, filt) if "sublime_text" in filename.lower(): Rhapsody = Popen([filename]) elif filename == '': pass else: dlgTitle = u"打开错误" strInfo = u"请打开Rhapsody程序" QMessageBox.critical(self, dlgTitle, strInfo) sleep(self.openRhapsodyTime) # 5秒 #打开工程编译的.exe文件 if path.isfile(self.RhapsodyProjectExePath): if '.exe' in self.RhapsodyProjectExePath: ShellExecute(0, 'open', self.RhapsodyProjectExePath, "", '', 1) # print("打开rhapsody成功!!!") else: curPath = QDir.currentPath() dlgTitle = u"打开Rhapsody项目编译之后可执行文件" filt = u"执行程序(*.exe);;所有文件(*.*)" filename, _ = QFileDialog.getOpenFileName(self, dlgTitle, curPath, filt) if ".exe" in filename.lower(): ShellExecute(0, 'open', filename, "", '', 1) elif filename == '': pass else: dlgTitle = u"打开错误" strInfo = u"打开Rhapsody项目编译之后可执行文件" QMessageBox.critical(self, dlgTitle, strInfo) sleep(self.openRhapsodyExeTime) # 这个时间是等待Rhapsody加载工程 # TODO: 模拟键盘发送一个F4, 问题怎么把软件的焦点防御rhapsody # 先获取焦点 hand = None try: for hwnd in get_hwnds_for_pid(Rhapsody.pid): print(hwnd, "=>", GetWindowText(hwnd)) keybd_event(13, 0, 0, 0) hand = hwnd SetForegroundWindow(hwnd) sleep(0.1) # 按下快捷键 keybd_event(115, 0, 0, 0) #F4键位码是115 sleep(0.01) keybd_event(115, 0, KEYEVENTF_KEYUP, 0) #释放按键115 break except UnboundLocalError: dlgTitle = u"打开错误" strInfo = u"打开Rhapsody程序打开错误" QMessageBox.critical(self, dlgTitle, strInfo) sleep(0.5) mainWindow = MainWindow("mainSystemButton", hand) mainWindow.start()
from win32api import ShellExecute ShellExecute( 0, "open", "C:\\Program Files\\JetBrains\\PyCharm 2020.2.1\\bin\\pycharm64.exe", "", "", 0)
def _printfile(fn): """Print the given file using the default printer.""" rv = ShellExecute(0, "print", fn, None, home, 0) if 0 < rv <= 32: messagebox.showerror("Printing failed", f"Error code: {rv}")
self.OnMessage("初始化成功") self.OnMessage("副本包括(御魂,觉醒,业原火,御灵)") if len(self.mTowerDropList) > 0: self.OnMessage( "已选择:探索第%d章(单人探索生效)" % self.mTowerDropList[self.mTowerDropBox.currentIndex()]) def main(): app = QApplication(sys.argv) app.setApplicationName("鸡jio v4.9") try: shell = wcdp("WScript.Shell") # 窗口置顶,有这个不会失败 shell.SendKeys('%') window = JiJioGUI() except: ctrller.WriteErrorLog() exit(0) sys.exit(app.exec_()) if __name__ == '__main__': if len(sys.argv) < 2: try: if not ctypes.windll.shell32.IsUserAnAdmin(): ShellExecute(None, u'runas', sys.executable, __file__, None, 1) sys.exit(0) except: sys.exit(0) main()
def __call__(self): try: ShellExecute(0, None, process_name, self.value, process_path, 0) return True except: raise self.Exceptions.ProgramNotFound
def runCmd(self, i): Thread(target=lambda: ShellExecute(0, "open", self.appDIR + "projects\\{}".format(i), "", "", 0)).start()