1
Is there any way or command to run a Python script with administrator privileges?
1
Is there any way or command to run a Python script with administrator privileges?
3
If you are on linux, just run sudo:
sudo python meuScript.py
In the case of windows (since you mentioned administrator instead of root, I suppose this is the case), there are some options:
You can run the terminal with administrator privileges.
Start -> cmd -> right click -> Run as administrator.
You can also press CTRL+SHIFT+ENTER after typing cmd. After that, just run the script normally.
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)
Source: Stackoverflow
Browser other questions tagged python python-3.x
You are not signed in. Login or sign up in order to post.
Your question is too wide or doesn’t seem to be about programming.
– Wallace Maxters
Which operating system used? Are you facing any problem while running code normally?
– Wallace Maxters