Reputation: 1118
I have my own python script that manages the IP address on my computer. Mainly it executes the netsh command in the command line (windows 10) which for you must have administrator rights.
It is my own computer, I am the administrator and when running the script I am already logged in with my user (Adrian) which is of type administrator.
I can`t use the right click and "run as administrator" solution because I am executing my netsh command from my python script.
Anybody knows how to get "run as administrator" with a command from CMD ?
Thanks
Upvotes: 4
Views: 8728
Reputation: 1391
You can launch the subprocess via NirCmd.
http://www.nirsoft.net/utils/nircmd.html
Upvotes: 0
Reputation:
You can request UAC elevation from within your Python script.
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)
else:
print "I'm elevated!"
sys.exit(0)
Upvotes: 0