0

How can I run a batch file using an elevated account without the UAC dialog popping up, If I know the password for the account I am trying to use? I am looking for a pure batch/powershell answer, if at all possible.

cascading-style
  • 247
  • 1
  • 3
  • 12

2 Answers2

1

You normally wouldn't want to do this, in general in breaches security and the point behind elevating the execution, and bypassing the Admin request.

But from my understand you are able to run a batch file with administrative rights, but this cannot be done with the batch file itself.

I may be mistaken, but I believe the question has already been asked and resolved here.

As mentioned in the above link you could preform the following:

Right click batch file > Send to > Desktop (create shortcut)

Another user had also mentioned a new solution here

https://superuser.com/a/852877/676838

REM --add the following to the top of your bat file--


@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 )

:UACPrompt
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

:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
1

You can't run it as an elevated user without the UAC prompts unless it's turned off.

However, there is another method; use:

psexec -u username -p password

This way, it will execute the batch file with elevation .

fixer1234
  • 28,064
Elie
  • 552