Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have found the following routine which is supposed to allow a batch file to issue a UAC prompt and elevate itself to admin. Problem is on Server 2012 it doesn't seem to work for me. According to the notes I have read when a correct admin username/password is entered it should just continue with any code written beneath the below routine.

@echo off

:: BatchGotAdmin
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    exit /B

    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
share|improve this question

I have not found any way to elevate batch files without the help of other programs. What i found is a tool which does the magic, because I do not like to do all the vbs-stuff.

I have successfully tested a call which might look like this

2>nul 1>nul start runasadmin.exe "%~dpf0"&&exit

This code calls it self with runasadmin.exe (i renamed it from elevate.exe) and if it was started it exits the non-elevated program.

Hope this helps on Server 2012!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.