Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

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

 

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style