Start Windows batch file maximized
I've written a batch file that I plan on distributing to a few dozen machines. It automatically checks the working state of several devices. I recently added a "menu" at the start of the script, prompting the user to select specific items to query from a list. The list, however, is too long to see without scrolling.
Rather than refining my list, what can I add to the batch to start the Windows shell maximized? I tried to cheat and Right click the .bat -> Properties -> Change the "Run" state to "Maximized"
, but this option does not exist (and frankly I'd rather add this feature within the script itself).
The machines that are running the script are running Windows 7
Solution 1:
You can try start /MAX yourscript.bat
to start your script in a maximized cmd (up to Windows 7)
Edit (by Rik):
I've created a small example which shows how you could do it all in one batch-file
(without a separate launcher):
@echo off
if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
:: here comes the rest of your batch-file
echo "test"
pause
There will be a slight flicker of the original batch-file (which will exit immediately) before starting the maximized version.
Simple explanation:
If the batch is not called with the parameter max
we call itself again (%0
), this time maximized with the help of start /max
, and with the parameter max
and that way the second time its called it will skip the if-statement and continue with your commands.
Breakdown:
-
if not "%1" == "max"
execute the next command only if%1
is not "max".%1
stands for the first parameter given to the batch-file. Somy_batch.bat max
will havemax
in the%1
-variable. If we didn't start the batch with amax
parameter we need to execute this line. -
start /MAX
start the command after it, in maximized form. -
cmd /c
executecmd.exe
and/c
means exit afterwards. -
%0 max
. The%0
stands for your own batch-file name and heremax
is its first parameter. This means we need to skip that firstif
-line or else we get caught in a loop :) -
& exit/b
: The&
means execute the next command simultaneous with the previous. This means we executed thestart /max your batchfile
and in the meantime exit the current batch.
This also means we can't call this version with any other parameters than max
. If your batch-files needs a parameter to start then you'll need to do some more magic (like shift
ing the %1 after testing).
If that's the case let us know.