Windowsでバッチファイルを管理者として実行したい

この記事では、Windowsでバッチファイルを管理者として実行する方法をご紹介していきます。
Windowsでバッチファイルを管理者として実行する方法

@echo off cd /d %~dp0 for /f "tokens=3 delims=\ " %%i in ('whoami /groups^|find "Mandatory"') do set LEVEL=%%i if NOT "%LEVEL%"=="High" ( powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -Command "Start-Process %~f0 -Verb runas" exit ) rem
PowerShellスクリプトでも、自動的に管理者として実行させることが可能です。下記の処理を冒頭に追記しましょう。
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) { Start-Process powershell.exe "-File `"$PSCommandPath`"" -Verb RunAs exit } rem



