How to use 'run python as admin' in Python

Every line of 'run python as admin' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
13def _managepy(args, djangoenv='develop', environment={}):
14 with shell_env(DJANGOENV=djangoenv, **environment):
15 local('python manage.py {args}'.format(args=args))
95def RunAsAdminWin32():
96 # FIXME ... what happens if "frozen"
97 script = os.path.abspath(sys.argv[0])
98 if sys.executable != script:
99 params = ' '.join([script] + sys.argv[1:])
100 else:
101 params = ' '.join(sys.argv[1:])
102
103 # fMask = 0
104 fMask = win32com.shell.shellcon.SEE_MASK_NO_CONSOLE
105 # fMask=win32com.shell.shellcon.SEE_MASK_NOCLOSEPROCESS
106 try:
107 win32com.shell.shell.ShellExecuteEx(
108 nShow=win32con.SW_SHOWNORMAL,
109 fMask=fMask,
110 lpVerb='runas',
111 lpFile=sys.executable,
112 lpParameters=params)
113 except pywintypes.error, e:
114 return False, e[2]
115
116 # If ShellExecuteEx was ok ... this will never be reached
117 # return True, None
118 # In any case exit to avoid a "single instance check" failure
119 sys.exit(0)

Related snippets