import ctypes
import sys
def admin():
try: return ctypes.windll.shell32.IsUserAnAdmin()
except Exception: return False
if not admin(): # If not ran as administrator, re-run it as administrator!
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
sys.exit()