nwnc.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:NoWannaNoCry 作者: dolang 项目源码 文件源码
def run_as_admin(extra_args=None):
    """If required, rerun the script and request admin privileges.

    :params iterable extra_args:
        Additional arguments to pass to the script in case it has to be
        restarted.
    """
    if not am_admin():
        try:
            print('Restarting and requesting admin privileges.')
            args = sys.argv
            if extra_args:
                args = args + extra_args
            exe, args = sys.executable, ' '.join(args)
            if sys.version_info[0] == 2:
                exe = _decode(exe)
            ctypes.windll.shell32.ShellExecuteW(None, 'Runas', exe, args, None, 1)
            sys.exit()
        except Exception as e:
            print(e)
            msg = ('Unable to elevate privileges. You need to rerun the script'
                   ' with Administrator privileges yourself. E.g. try pressing'
                   ' the Windows key + x, then select "Command Prompt (Admin)"'
                   ' and run the script in that console.')
            sys.exit(msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号