本文整理汇总了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