python 管理员运行命令

刚刚看帖子,看到 @王玉超 同学的问题,如何利用 python 进行管理员的方式运行浏览器。
下面呢,是解决的代码:

from __future__ import print_function
import ctypes, sys


def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False


if is_admin():
    # 将要运行的代码加到这里
    # 这里可以将打开浏览器的运行代码放进去,运行前可以看到蹦出授权管理员的窗口
else:
    if sys.version_info[0] == 3:
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
    else:  # in python2.x
        ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)