Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Run Batch file minimized

26 views
Skip to first unread message

Dave Pink

unread,
Jan 31, 2002, 1:17:53 PM1/31/02
to
The following code causes a batch file to run minimized:

If NOT DEFINED ME Set ME=1&Goto :EOF&Start "ME" /MIN %0

The code works fine in NT4. Doesn't work in Windows 2000. Can anyone
modify the code so that it does? Thanks.

------------------------- Original Post -----------------------------

From: Frank (oswig...@rhurvieoywffwmps.com)
Subject: Re: DOS Batch file minimized
Newsgroups: alt.msdos.batch.nt
Date: 2001-11-30 08:46:41 PST

Dave Pink <fa516b59.01113...@posting.google.com>...

^ > ^ 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

Ritchie

unread,
Feb 3, 2002, 11:22:42 AM2/3/02
to
"Dave Pink" <tron...@msn.com> wrote in message
news:fa516b59.02013...@posting.google.com...

> The following code causes a batch file to run minimized:
>
> If NOT DEFINED ME Set ME=1&Goto :EOF&Start "ME" /MIN %0
>
> The code works fine in NT4. Doesn't work in Windows 2000. Can anyone
> modify the code so that it does? Thanks.

I see what you mean! This tweaked version works on NT4(SP6a)
and W2K(SP2): -

If NOT DEFINED ME Set ME=1&Start "ME" /MIN %0&Goto :EOF

--
Ritchie

Dave Pink

unread,
Feb 4, 2002, 12:14:46 PM2/4/02
to
That works. Thanks Ritchie!

---------------------------------------------------------------------------

"Ritchie" <dontg...@enildnammoc.co.uk> wrote in message news:<3c5d6...@mk-nntp-1.news.uk.worldonline.com>...

0 new messages