def RunAsAdminWin32():
# FIXME ... what happens if "frozen"
script = os.path.abspath(sys.argv[0])
if sys.executable != script:
params = ' '.join([script] + sys.argv[1:])
else:
params = ' '.join(sys.argv[1:])
# fMask = 0
fMask = win32com.shell.shellcon.SEE_MASK_NO_CONSOLE
# fMask=win32com.shell.shellcon.SEE_MASK_NOCLOSEPROCESS
try:
win32com.shell.shell.ShellExecuteEx(
nShow=win32con.SW_SHOWNORMAL,
fMask=fMask,
lpVerb='runas',
lpFile=sys.executable,
lpParameters=params)
except pywintypes.error, e:
return False, e[2]
# If ShellExecuteEx was ok ... this will never be reached
# return True, None
# In any case exit to avoid a "single instance check" failure
sys.exit(0)
评论列表
文章目录