Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

[バッチ] 管理者権限でバッチを起動する

Last updated at Posted at 2021-03-10

管理者権限でなければその旨表示して終わるパターン

参考
https://pasomaki.com/winbatch-check-admin/

net sessionコマンドが管理者でしか実行できないことを利用して、管理者権限かどうかを判定する。

@echo off
 
net session >nul 2>&1

echo %ERRORLEVEL%

if %ERRORLEVEL% neq 0 (
  echo 管理者権限で起動してください。
  goto FINISH
)

rem 管理者権限でやる処理をここに書く

:FINISH

pause

起動時に管理者権限でなければ管理者に聞くパターン

こちらの記事のがそのまま使えそう。
https://qiita.com/noonworks/items/0452d0019b68203bc287

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?