I have some .cmd files which need to be run as admin. They have this at the start of each file, to detect if not running as admin, and re-launch as an admin if not:
:: If not admin, restarts the script with admin privileges
NET FILE 1>nul 2>nul
if '%errorlevel%' == '0' (
goto adminTasks
) else (
echo Restarting with admin privileges...
POWERSHELL saps -filepath '%0' -verb runas 1>nul 2>nul
)
exit /b
:adminTasks
:: bla bla bla
The petty thing that’s bugging me is that I’ve just downloaded Windows Terminal, and set it as my default terminal application in the settings. When I run this script, it now briefly opens in terminal, but when it closes and I hit yes to the admin prompt, it opens it back in old windows command prompt.
I’ve played around and noticed if I use start-process to run a .cmd file, if I include “-verb runas”, it always uses command prompt. If I omit that, it uses terminal.
Anyone have any idea what’s going on? Am I being an idiot?
Max Sandberg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.