Last active
December 13, 2016 00:21
-
-
Save srz-zumix/932c30a229cfb00502b6fb1f811e0187 to your computer and use it in GitHub Desktop.
This file contains 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
@echo off | |
rem 管理者権限があるかどうかチェック | |
whoami /PRIV | find "SeLoadDriverPrivilege" >NUL | |
if not errorlevel 1 goto start | |
rem ない場合は powershell 経由で自分自身を実行 | |
rem %0 のドライブレターで検索して UNC パスを取得 | |
for /f "usebackq tokens=1,2,3" %%i in (`net use`) do if "%%j" == "%~d0" SET UNC=%%k | |
rem net use で割当をしてから実行(既に割当たっている場合もあるので成否にかかわらずコマンド実行) | |
powershell.exe -Command Start-Process -FilePath cmd.exe -ArgumentList '/c "net use %~d0 %UNC% || %~dp0%~nx0"' -Wait -Verb Runas | |
goto :EOF | |
:start | |
cd /d %~dp0 | |
rem ここからバッチ本来の処理 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment