本文整理匯總了Python中win32com.shell.shell.ShellExecuteEx方法的典型用法代碼示例。如果您正苦於以下問題:Python shell.ShellExecuteEx方法的具體用法?Python shell.ShellExecuteEx怎麽用?Python shell.ShellExecuteEx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32com.shell.shell
的用法示例。
在下文中一共展示了shell.ShellExecuteEx方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: UseCommandLine
# 需要導入模塊: from win32com.shell import shell [as 別名]
# 或者: from win32com.shell.shell import ShellExecuteEx [as 別名]
def UseCommandLine(*classes, **flags):
unregisterInfo = '--unregister_info' in sys.argv
unregister = '--unregister' in sys.argv
flags['quiet'] = flags.get('quiet',0) or '--quiet' in sys.argv
flags['debug'] = flags.get('debug',0) or '--debug' in sys.argv
flags['unattended'] = flags.get('unattended',0) or '--unattended' in sys.argv
if unregisterInfo:
return UnregisterInfoClasses(*classes, **flags)
try:
if unregister:
UnregisterClasses(*classes, **flags)
else:
RegisterClasses(*classes, **flags)
except win32api.error, exc:
# If we are on xp+ and have "access denied", retry using
# ShellExecuteEx with 'runas' verb to force elevation (vista) and/or
# admin login dialog (vista/xp)
if flags['unattended'] or exc.winerror != winerror.ERROR_ACCESS_DENIED \
or sys.getwindowsversion()[0] < 5:
raise
ReExecuteElevated(flags)
示例2: ExplorePIDL
# 需要導入模塊: from win32com.shell import shell [as 別名]
# 或者: from win32com.shell.shell import ShellExecuteEx [as 別名]
def ExplorePIDL():
pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
print "The desktop is at", shell.SHGetPathFromIDList(pidl)
shell.ShellExecuteEx(fMask=shellcon.SEE_MASK_NOCLOSEPROCESS,
nShow=win32con.SW_NORMAL,
lpClass="folder",
lpVerb="explore",
lpIDList=pidl)
print "Done!"
示例3: request_admin_privileges
# 需要導入模塊: from win32com.shell import shell [as 別名]
# 或者: from win32com.shell.shell import ShellExecuteEx [as 別名]
def request_admin_privileges():
ASADMIN = 'asadmin'
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable,
lpParameters=params, nShow=win32con.SW_SHOW)
sys.exit(0)
示例4: launch_console
# 需要導入模塊: from win32com.shell import shell [as 別名]
# 或者: from win32com.shell.shell import ShellExecuteEx [as 別名]
def launch_console(params, visible=True, process=sys.executable, visiblity_override=None):
if visiblity_override is not None:
if visiblity_override:
process.replace('pythonw', 'python')
else:
process = process.replace('python', 'pythonw').replace('pythonww', 'pythonw')
try:
shell.ShellExecuteEx(lpVerb='runas', lpFile=process, lpParameters=params, nShow=5 if visible else 0)
except pywintypes.error:
return False
return True
示例5: runAsAdmin
# 需要導入模塊: from win32com.shell import shell [as 別名]
# 或者: from win32com.shell.shell import ShellExecuteEx [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