本文整理汇总了Python中win32api.ShellExecute方法的典型用法代码示例。如果您正苦于以下问题:Python win32api.ShellExecute方法的具体用法?Python win32api.ShellExecute怎么用?Python win32api.ShellExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32api
的用法示例。
在下文中一共展示了win32api.ShellExecute方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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 = None
self.PrintError(self.text.text2 % exe)
return res
示例2: 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't
bargs = 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 duplicated
win32api.ShellExecute(0, "open", args[0], argstr, None, 1) # 1 == SW_SHOW
else:
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
示例3: 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
示例4: 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
)
#===============================================================================
示例5: 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")
示例6: 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.python.net/crew/mhammond/win32", None, "", 1)
示例7: 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 win32help
global 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 fileName
finally:
win32ui.DoWaitCursor(-1)
示例8: 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)
示例9: __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
示例10: __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
)
示例11: 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)
示例12: __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)
示例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 win32api
import win32con
import win32event
import win32process
from win32com.shell.shell import ShellExecuteEx
from win32com.shell import shellcon
python_exe = sys.executable
if cmdLine is None:
cmdLine = [python_exe] + sys.argv
elif 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_SHOWNORMAL
showCmd = 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 = None
return rc