![Share on Facebook Facebook](https://www.rootlinks.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/facebook.png)
![Share on Twitter twitter](https://www.rootlinks.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/twitter.png)
![Share by email mail](https://www.rootlinks.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/mail.png)
Winaeroに下記の記事がありました
How to check in a batch file if you are running it elevated
http://winaero.com/blog/how-to-check-in-a-batch-file-if-you-are-running-it-elevated/
このサイトはWindows関連の色々な裏ワザやTipsを紹介してくれているので購読しているサイトです
今回の記事はバッチファイルが管理者権限で実行しているかどうかを判断するものです
判断には管理者権限が無いと動作しないコマンドopenfilesを実行してエラーレベルで判断する方法です
バッチファイルのサンプル
1 2 3 4 5 6 7 8 9 |
@echo off openfiles > NUL 2>&1 if NOT %ERRORLEVEL% EQU 0 goto NotAdmin echo 管理者権限で実行中 goto End :NotAdmin echo 一般権限で実行中 :End |