Created
March 7, 2018 14:40
-
-
Save masamitsu-murase/1f93636ca11901ab0cd0591509c6d031 to your computer and use it in GitHub Desktop.
Run Python script as Administrator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@goto BEGINNING_OF_CMD | |
# -*- coding: UTF-8 -*- | |
""" | |
:BEGINNING_OF_CMD | |
@echo off | |
cd /d "%~dp0" | |
set PYTHON=python.exe | |
%PYTHON% -c "import ctypes, sys, ctypes.wintypes; ctypes.windll.shell32.IsUserAnAdmin.restype = ctypes.wintypes.BOOL; sys.exit(ctypes.windll.shell32.IsUserAnAdmin())" | |
if ERRORLEVEL 2 goto :ERROR | |
if ERRORLEVEL 1 goto :ADMIN | |
goto :NON_ADMIN | |
:ADMIN | |
%PYTHON% -x "%~nx0" | |
exit /b %ERRORLEVEL% | |
:NON_ADMIN | |
powershell Start-Process "%~0" -Verb runas | |
exit /b 0 | |
:ERROR | |
echo IsUserAnAdmin failed. | |
exit /b 1 | |
""" | |
print("hoge") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment