1

How can I get the UAC prompt to give my Python code Admin rights? I have tried this but Python 32 Bit or my Terminal just freezes:

    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"
JRKGaming
  • 31
  • 1
  • This question may help you. [Ask for admin access for a Python function in Windows](https://stackoverflow.com/questions/41851413/ask-for-admin-access-for-a-python-function-in-windows) – Dilshan Apr 13 '21 at 04:43

1 Answers1

0

You can make a shortcut somewhere and as the target use: python yourscript.py then under properties and advanced select run as administrator.

When the user executes the shortcut it will ask them to elevate the application.

Manoj
  • 199
  • 4
  • 15