Here is my quick and easy way to raise the privilage level of a Windows Batch script; allowing you to run your code at an administrator level.

This is not a new question and has been asked many times on StackOverflow forums. The best answer I was able to find was the following from dbenham:

That being said there are many ways to skin this cat, so I came up with my own method, all be it derivative. The main difference in the following code is that you will always get a UAC prompt in my variant of the code, even if you are currently running it as an account that is a member of the local administrators group:

invoke UAC in a Windows Batch script - UAC prompt UAC prompt invoked! Full Code:

:: Automatically check & get admin rights
@echo off
ECHO =============================
ECHO Running Admin shell
ECHO =============================

if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

if '%1'=='ELEV' (shift & goto gotPrivileges)
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC: CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
exit /B

setlocal & pushd .

ECHO Hello World, I am your admin:

Find the code on GitHub: