title: Requesting UAC elevation in a python script
body: <p>I need my python script to have elevated UAC privileges. I have tried again and again and can NOT figure it out.</p>
  
  <p>This is my code right now:</p>
  
  <pre><code>from win32com.shell.shell import ShellExecuteEx
  from win32com.shell import shellcon
  import win32process, win32event
  import win32con
  from ntsecuritycon import *
  
  ASADMIN = 'asadmin'
  
  if sys.argv[-1] != ASADMIN:
      script = os.path.abspath(sys.argv[0])
      params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
      ShellExecuteEx(fMask=shellcon.SEE_MASK_NOCLOSEPROCESS,
                      lpVerb="runas",
                      lpFile=sys.executable,
                      lpParameters=params,
                      nShow=win32con.SW_SHOW)
      sys.exit(0)
  </code></pre>
  
  <p>Now, the information I have so far is that this will run without errors, and it does reopen itself. The reopened script returns </p>
  
  <pre><code>["c:\\users\\justin\\UAC.py", "asadmin"]
  </code></pre>
  
  <p>for </p>
  
  <pre><code>sys.argv
  </code></pre>
  
  <p>, but it still won't let me perform admin tasks.</p>
  
  <p>Although help with fixing this code would be optimal, I'm also ready to try anything else that works, thanks!</p>