【问题标题】:How an I get an U.A.C prompt for Administrator rights in Python如何在 Python 中获得管理员权限的 U.A.C 提示
【发布时间】:2021-07-08 03:22:33
【问题描述】:

如何获得 UAC 提示以授予我的 Python 代码管理员权限?我已经尝试过了,但 Python 32 位或我的终端只是冻结:

    import os
    import sys
    import win32com.shell.shell as shell
    ASADMIN = 'asadmin'

    if sys.argv[-1] != ASADMIN:
         script = os.path.abspath(sys.argv[0])
         params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
         shell.ShellExecuteEx(lbVerb='runas', lpFile=sys.executable, lpParameters=params)
         sys.exit(0)
    with open("somefile.txt", "w") as out:
         print >> out, "i am root"

【问题讨论】:

标签: python ruby windows admin uac


【解决方案1】:

您可以在某处创建快捷方式并作为目标使用:python yourscript.py 然后在属性和高级选择下以管理员身份运行。

当用户执行快捷方式时,它会要求他们提升应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    相关资源
    最近更新 更多