I used multiple examples to patch this working one liner together.
This will open your batch script as an ADMIN + Maximized Window
Just add one of the following codes to the top of your batch script.
Both ways work, just different ways to code it.
I believe the first example responds the quickest due to /d
switch disabling my doskey commands that I have enabled..
EXAMPLE ONE
@ECHO OFF
IF NOT "%1"=="MAX" (powershell -WindowStyle Hidden -NoProfile -Command {Start-Process CMD -ArgumentList '/D,/C' -Verb RunAs} & START /MAX CMD /D /C %0 MAX & EXIT /B)
:--------------------------------------------------------------------------------------------------------------------------------------------------------------------
:: Your original batch code here:
:--------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXAMPLE TWO
@ECHO OFF
IF NOT "%1"=="MAX" (powershell -WindowStyle Hidden -NoProfile -Command "Start-Process CMD -ArgumentList '/C' -Verb RunAs" & START /MAX CMD /C "%0" MAX & EXIT /B)
:--------------------------------------------------------------------------------------------------------------------------------------------------------------------
:: Your original batch code here:
:--------------------------------------------------------------------------------------------------------------------------------------------------------------------
See below for recommendations when using your original batch code
Place the original batch code in it's entirety
Just because the first line of code at the very top has @ECHO OFF
doesn't mean you should not include it again if your original script
has it as well.
This ensures that when the script get's restarted in a new window now running in admin
mode that you don't lose your intended script parameters/attributes...
Such as the current working directory, your local variables, and so on
You could beginning with the following commands to avoid some of these issues
:: Make sure to use @ECHO OFF if your original code had it
@ECHO OFF
:: Avoid clashing with other active windows variables with SETLOCAL
SETLOCAL
:: Nice color to work with using 0A
COLOR 0A
:: Give your script a name
TITLE NAME IT!
:: Ensure your working directory is set where you want it to be
:: the following code sets the working directory to the script directory folder
PUSHD "%~dp0"
THE REST OF YOUR SCRIPT HERE...
:: Signal the script is finished in the title bar
ECHO.
TITLE Done! NAME IT!
PAUSE
EXIT