This is not about running a batch script as admin per, but rather how to elevate another program from batch...
I have a batch file "wrapper" for an exe. They have the same "root file name", but alternate extensions. I am able to launch the exe as admin, and set the working directory to the one containing the script, with the following one line powershell invocation:
@powershell "Start-Process -FilePath '%~n0.exe' -WorkingDirectory '%~dp0' -Verb RunAs"
There are a whole slew of additional Start-Process
options as well that you can apply! Check out: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-6
Note that I use the @
prefix. That's equivalent to @echo off
for the one line. I use %~n0
here to get the "root name" of the batch script, then I concatenate the .exe
to point it the adjancent binary. The use of %~dp0
provides the full path to the directory which the batch resides. And, of course, the -Verb RunAs
parameter provides the elevation.