分享

Python win32api.ShellExecute方法代碼示例

 GTY_TSG 2021-07-31

本文整理匯總了Python中win32api.ShellExecute方法的典型用法代碼示例。如果您正苦於以下問題:Python win32api.ShellExecute方法的具體用法?Python win32api.ShellExecute怎麽用?Python win32api.ShellExecute使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在<a href="https:///zh-tw/examples/detail/python-module-win32api.html" win32api的用法示例。

在下文中一共展示了win32api.ShellExecute方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: spawn

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def spawn(*args):if os.name == 'nt':# do proper argument quoting since exec/spawn on Windows doesn'tbargs = args args = []for a in bargs:if not a.startswith('/'): a.replace(''', '\'') a = ''%s'' % a args.append(a) argstr = ' '.join(args[1:])# use ShellExecute instead of spawn*() because we don't want# handles (like the controlsocket) to be duplicatedwin32api.ShellExecute(0, 'open', args[0], argstr, None, 1) # 1 == SW_SHOWelse:if os.access(args[0], os.X_OK): forkback = os.fork()if forkback == 0:# BUG: stop IPC!print 'execl ', args[0], args os.execl(args[0], *args)else:#BUG: what should we do here?pass
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:27,代碼來源:platform.py


示例2: RunEmailClient

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def RunEmailClient(text):'''Get the path of default email client through querying the
        Windows registry. '''try:
        em_reg = _winreg.OpenKey(
            _winreg.HKEY_CLASSES_ROOT,'\\mailto\\shell\\open\\command')
        EmPath = _winreg.EnumValue(em_reg,0)[1]
        _winreg.CloseKey(em_reg)
        EmPath = EmPath.split(''')[1]except:
        eg.PrintError(text.error9)else:
        head, tail = os.path.split(EmPath)
        win32api.ShellExecute(0,None,
            tail,None,
            head,1)#===============================================================================
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:26,代碼來源:__init__.py


示例3: NeedApp

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def NeedApp():import win32ui rc = win32ui.MessageBox(NeedAppMsg % sys.argv[0], 'Demos', win32con.MB_YESNO)if rc==win32con.IDYES:try: parent = win32ui.GetMainFrame().GetSafeHwnd() win32api.ShellExecute(parent, None, 'pythonwin.exe', '/app '%s'' % sys.argv[0], None, 1)except win32api.error, details: win32ui.MessageBox('Error executing command - %s' % (details), 'Demos')
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:demoutils.py


示例4: OnButHomePage

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def OnButHomePage(self, id, code):if code == win32con.BN_CLICKED:
            win32api.ShellExecute(0, 'open', 'http://starship./crew/mhammond/win32', None, '', 1)
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:app.py


示例5: OpenHelpFile

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def OpenHelpFile(fileName, helpCmd = None, helpArg = None):'Open a help file, given a full path'# default help arg.win32ui.DoWaitCursor(1)try:if helpCmd is None: helpCmd = win32con.HELP_CONTENTS ext = os.path.splitext(fileName)[1].lower()if ext == '.hlp': win32api.WinHelp( win32ui.GetMainFrame().GetSafeHwnd(), fileName, helpCmd, helpArg)# XXX - using the htmlhelp API wreaks havoc with keyboard shortcuts# so we disable it, forcing ShellExecute, which works fine (but# doesn't close the help file when Pythonwin is closed.# Tom Heller also points out http://www.microsoft.com/mind/0499/faq/faq0499.asp,# which may or may not be related.elif 0 and ext == '.chm':import win32helpglobal htmlhelp_handle helpCmd = html_help_command_translators.get(helpCmd, helpCmd)#frame = win32ui.GetMainFrame().GetSafeHwnd()frame = 0 # Dont want it overlapping ours!if htmlhelp_handle is None: htmlhelp_hwnd, htmlhelp_handle = win32help.HtmlHelp(frame, None, win32help.HH_INITIALIZE) win32help.HtmlHelp(frame, fileName, helpCmd, helpArg)else:# Hope that the extension is registered, and we know what to do!win32api.ShellExecute(0, 'open', fileName, None, '', win32con.SW_SHOW)return fileNamefinally: win32ui.DoWaitCursor(-1)
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:31,代碼來源:help.py


示例6: shellopen

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def shellopen(cmd, path, cwd=None):return win32api.ShellExecute(None, cmd, path, None, cwd,
                                 win32con.SW_SHOWDEFAULT)
開發者ID:euske,項目名稱:pyrexecd,代碼行數:5,代碼來源:__init__.py


示例7: __call__

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]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# Now we can start to define the plugin by sub-classing eg.PluginClass
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:17,代碼來源:__init__.py


示例8: Execute

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def Execute(self, exe, path):try:
            res = ShellExecute(0,None,
                exe,None,
                path,1)except:
            res = Noneself.PrintError(self.text.text2 % exe)return res
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:16,代碼來源:__init__.py


示例9: __call__

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def __call__(self, cmdLineArgs=''):vlcPath = GetVlcPath()return ShellExecute(0,None, vlcPath, self.GetCmdLineArgs(cmdLineArgs),None, #os.path.dirname(vlcPath),1)
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:12,代碼來源:__init__.py


示例10: OpenHelpPage

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def OpenHelpPage(self,html_page):try:
            head, tail = os.path.split(self.IrfanViewPath)return win32api.ShellExecute(0,None,'hh.exe',
                ('mk:@MSITStore:'+head+'\i_view32.chm::/'                +html_page).encode(myEncoding),
                os.environ['SYSTEMROOT'],1)except:
            self.PrintError(self.text.err)
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:16,代碼來源:__init__.py


示例11: __call__

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def __call__(self,label,cmdline):try: head, tail = os.path.split(self.plugin.IrfanViewPath)return win32api.ShellExecute(0,None, tail, cmdline.encode(myEncoding), head,1)except: self.PrintError(self.text.err)
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:15,代碼來源:__init__.py


示例12: printPdf

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def printPdf(self, printer, data):defaultPrinter = win32print.GetDefaultPrinter()
            win32print.SetDefaultPrinter(printer)with tempfile.NamedTemporaryFile(suffix='.pdf', delete=False) as f:
                f.write(base64.b64decode(data))
                f.flush()
                filename = os.path.basename(f.name)
                dirname = os.path.dirname(f.name)
                win32api.ShellExecute(0, 'print', filename, None, dirname, 0)
            win32print.SetDefaultPrinter(defaultPrinter)return 0
開發者ID:akretion,項目名稱:pywebdriver,代碼行數:13,代碼來源:win32print_driver.py


示例13: runAsAdmin

# 需要導入模塊: import win32api [as 別名]# 或者: from win32api import ShellExecute [as 別名]def runAsAdmin(cmdLine=None, wait=True):if os.name != 'nt':raise RuntimeError, 'This function is only implemented on Windows.'import win32apiimport win32conimport win32eventimport win32processfrom win32com.shell.shell import ShellExecuteExfrom win32com.shell import shellcon python_exe = sys.executableif cmdLine is None: cmdLine = [python_exe] + sys.argvelif type(cmdLine) not in (types.TupleType, types.ListType):raise ValueError, 'cmdLine is not a sequence.'cmd = ''%s'' % (cmdLine[0],)# XXX TODO: isn't there a function or something we can call to massage command line params?params = ' '.join([''%s'' % (x,) for x in cmdLine[1:]]) cmdDir = ''#showCmd = win32con.SW_SHOWNORMALshowCmd = win32con.SW_HIDE lpVerb = 'runas' # causes UAC elevation prompt.# print 'Running', cmd, params# ShellExecute() doesn't seem to allow us to fetch the PID or handle# of the process, so we can't get anything useful from it. Therefore# the more complex ShellExecuteEx() must be used.# procHandle = win32api.ShellExecute(0, lpVerb, cmd, params, cmdDir, showCmd)procInfo = ShellExecuteEx(nShow=showCmd, fMask=shellcon.SEE_MASK_NOCLOSEPROCESS, lpVerb=lpVerb, lpFile=cmd, lpParameters=params)if wait: procHandle = procInfo['hProcess'] obj = win32event.WaitForSingleObject(procHandle, win32event.INFINITE) rc = win32process.GetExitCodeProcess(procHandle)# print 'Process handle %s returned code %s' % (procHandle, rc)else: rc = Nonereturn rc
開發者ID:ElevenPaths,項目名稱:uac-a-mola,代碼行數:51,代碼來源:admin.py



注:本文中的win32api.ShellExecute方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多