10-29-2020
08:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-29-2020
08:12 AM
I'm not aware of a way to make cmd files run as admin by default. But there is a trick to have a cmd file run it self as admin.
The code below will create a temporary vbs script that will run the cmd file with admin permissions. You just have to add your code to the payload section where noted.
@Anonymous off
if _%1_==_payload_ goto :payload
:getadmin
echo %~nx0: elevating self
set vbs=%temp%\getadmin.vbs
echo Set UAC = CreateObject^("Shell.Application"^) >> "%vbs%"
echo UAC.ShellExecute "%~s0", "payload %~sdp0 %*", "", "runas", 1 >> "%vbs%"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
goto :eof
:payload
echo %~nx0: running payload with parameters:
echo %*
echo ---------------------------------------------------
cd /d %2
shift
shift
echo PUT YOUR CODE HERE
goto :eof