TIA
Terry
^ Is there a way to make a dos screen either minimize or maximize from
within
^ the batch file that is running?
Sure. Use START with its minimize switch. Something like this:
If NOT DEFINED ME Set ME=1&Goto :EOF&Start "ME" /MIN %0
::Continue script.
Frank
> ^ Is there a way to make a dos screen either minimize or maximize from
> ^ within the batch file that is running?
>
>> Sure. Use START with its minimize switch. Something like this:
>>
>> If NOT DEFINED ME Set ME=1&Goto :EOF&Start "ME" /MIN %0
>> ::Continue script.
>>
>> Frank
Great piece of code Frank. One line, simple and clean. I remember
reading several previous posts that inquired how to run a batch file
minimized, and none of those proposed solutions was satisfactory.
Your code is working just fine for me...except when I use it in a
batch file that I pass a parameter to. For example, when I run the
following:
C:\>MybatchFile.bat MyParameter
my batch file blows up. Apparently the variable "%1" that I'm using in
my batch file is conflicting with your line of code. So I'm wondering
if you can break your line down for me and explain how it works. Then
maybe I can troubleshoot and find a solution to my problem. Thanks.
Dave
^ > ^ Is there a way to make a dos screen either minimize or maximize from
^ > ^ within the batch file that is running?
^ >> If NOT DEFINED ME Set ME=1&Goto :EOF&Start "ME" /MIN %0
^ >> ::Continue script.
^ Your code is working just fine for me...except when I use it in a
^ batch file that I pass a parameter to. For example, when I run the
^ following:
^
^ C:\>MybatchFile.bat MyParameter
My apologies, I neglected to include the parameters in the new command
line. This is what I should have written:
If NOT DEFINED ME Set ME=1&Goto :EOF&Start "ME" /MIN %0 %*
::Continue script.
The explanation that you requested:
If NOT DEFINED ME Set ME=1
This statement requires that the variable %ME% is not normally defined. It
doesn't have to be ME, it can be anything of your choosing. To make sure it
is something not normally defined, open "Start|Settings|Control Panel" and
run the "System" applet. Select the "Environment" tab and check both the
system and user variables. The variable you choose should not appear in
either location.
This also assumes that the batch file is run from an icon that you
double-click. If it is run from an existing console that has already been
used for some programs then any of those programs may have already set that
variable for some reason. Also, if this batch file is run more than once in
the same console then ME will remain defined by the initial instance of it.
To solve this possible problem include the line
Set ME=
at the end of your batch file so that it will always be executed when the
script ends.
If the variable ME doesn't exist then we make it exist. It doesn't matter
what the contents are, it just has to have contents. I used "1" because
it's short and implies TRUE.
Goto :EOF&Start "ME" /MIN %0 %*
I wrote those commands in the inverse order for readability. Since the
command interpreter reads the entire line and hands each statement to a
separate thread it doesn't matter what order they appear on the line. This
might be better conceptually:
If NOT DEFINED ME Set ME=1&Start "ME" /MIN %0 %*&Goto :EOF
Now, for this part:
Start "ME" /MIN %0 %*
The START command, contrary to what the documentation indicates, requires
that the title argument be included when run on NT4. The word "ME" was on
the top of my mind when I needed to choose a title so I just threw that in.
You can choose any title.
The switch /MIN obviously starts the process with a minimized window.
The variable '%0' is always defined by the command interpreter as the
current process. If you CALL a label from within a script then '%0' will be
the label name, so '%~f0', which is always the complete filename, would be
a better choice. And the variable '%*' is always the entire command line,
minus the program name. So '%0 %*', or '%~f0 %*', is the entire command
line. When the command interpreter reads the line it will substitute the
variables with their contents and the line will become:
Start "ME" /MIN MybatchFile.bat MyParameter
In summary, start the new process 'MybatchFile.bat' with the parameter
'MyParameter' and the window title "ME".
Goto :EOF
After the new process is started, the current instance of the script will
go directly to the built in label :EOF, which is always defined as the end
of the file. If you will be running this on older operating systems you may
need to add the :EOF label at the end of the script.
To summarize the entire line in one sentence:
If the variable ME does not exist, create it and run me as a new process,
then send this script to the end of the file.
When the new process is run it will see that the variable ME is already
defined and it will continue with the script, skipping the rest of the IF
statement.
REFERENCES:
SET/?
CALL/?
IF/?
Frank
I really appreciate the detailed explanation. Thanks a lot Frank.
Dave