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
  • 227
  • 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"
Anthony D.
  • 102
  • 4
  • This is what I am currently using for requesting UAC, however, as I said in my post, I am looking for a way to get elevation ***WITHOUT UAC*** and I already know the password. – cascading-style Dec 19 '16 at 19:26
  • 1
    You may be able to do so, if you create a shortcut based on the program either exe. or batch that you want to execute. You will basically need to create a shortcut that allows administrative rights to be applied. This may be what you are looking for. http://bit.ly/2i2anoj – Anthony D. Dec 19 '16 at 19:34
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
  • 27,064
  • 61
  • 75
  • 116
Elie
  • 534
  • 3
  • 16