how to run python script as admin
import ctypes, sys
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
# Code of your program here
else:
# Re-run the program with admin rights
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
4
16
import ctypes, os
def isAdmin():
""" Return True/Flase """
try:
is_admin = (os.getuid() == 0) # if Unis
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 # elese if Windows
return is_admin
Thank you!
16
0
Are there any code examples left?
New code examples in category Python