Answers for "python run as administrator windows"

1

open administrator command prompt using python

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(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
    sys.exit(0)
Posted by: Guest on March-30-2021
0

run file as administrator python

# Run file as administrator on Windows 7, 8, 10
# Tested for Python 3.8.5
import os

def RunAsAdmin(path_to_file,*args):
	os.system(r'Powershell -Command "Start-Process "'+path_to_file+'"'+ # CMD running Powershell
				' -ArgumentList @('+str(args)[1:-1]+')'+ # Arguments. [1:-1] to remove brackets
				' -Verb RunAs"' # Run file as administrator
	)

RunAsAdmin('cmd.exe','arg1','arg2')
Posted by: Guest on May-16-2021

Code answers related to "python run as administrator windows"

Python Answers by Framework

Browse Popular Code Answers by Language