Question: How do I run a batch file from another batch file with administrator rights?

I have tried the [RUNAS](http://ss64.com/nt/runas.html) command, but it requires the administrator password.

I am searching for an alternative for running a batch file by right clicking on it and running as an administrator. I want to automate it from another batch file.

Answer: 
Put each line in cmd or all of theme in the batch file:

```
@echo off

if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)

"Put your command here"

```

it works fine for me.
If you're trying to invoke a Windows [UAC](http://en.wikipedia.org/wiki/User_Account_Control) prompt (the one that puts the whole screen black and asks if you're granting administrator privileges to the following task), RUNAS is not the smoothest way to do it, since:

1. You're not going to get prompted for UAC authorization, even if logged in as the administrator and
2. RUNAS expects that you have the administrator password, even if your user is setup as a local administrator, in which case the former password is not a sound security practice, specially in work environments.

Instead, try to copy & paste the following code to ensure that your batch file runs with administrator privileges:

```
@echo off

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

if '%errorlevel%' NEQ '0' (
    echo Requesting Admin access...
    goto goUAC )
    else goto goADMIN

:goUAC
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:goADMIN
    pushd "%CD%"
    CD /D "%~dp0"

rem --- FROM HERE PASTE YOUR ADMIN-ENABLED BATCH SCRIPT ---
echo Stopping some Microsoft Service...
net stop sqlserveragent
rem --- END OF BATCH ----

```

This solution works 100% under Windows 7, 8.1 and 10 setups with UAC enabled.