How an I get an U.A.C prompt for Administrator rights in Python

  admin, python, ruby, uac, windows

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"

Source: Windows Questions

LEAVE A COMMENT