run file as administrator python

Solutions on MaxInterview for run file as administrator python by the best coders in the world

showing results for - "run file as administrator python"
Giovanni
17 Apr 2018
1# Run file as administrator on Windows 7, 8, 10
2# Tested for Python 3.8.5
3import os
4
5def RunAsAdmin(path_to_file,*args):
6	os.system(r'Powershell -Command "Start-Process "'+path_to_file+'"'+ # CMD running Powershell
7				' -ArgumentList @('+str(args)[1:-1]+')'+ # Arguments. [1:-1] to remove brackets
8				' -Verb RunAs"' # Run file as administrator
9	)
10
11RunAsAdmin('cmd.exe','arg1','arg2')