We help IT Professionals succeed at work.

I want "close on exit" in a Win2K .BAT

nrbreen
nrbreen asked
on
Medium Priority
934 Views
Last Modified: 2013-12-28
I am transferring a system from Win9x to Win2K

I have a "startup.bat" run from the startup folder which updates a few things, then starts several programs.
(The timing/order of startup is important.)

Win2K leaves the DOS window open when the batch has finished. (until you close the last of the programs, then the DOS window disappears.)

I want the DOS window to close as soon as the startup operations have completed - the startup.bat is finished. (as it does in Win9x with the "close on exit" option)

The situation can be easily replicated - e.g. a batch that starts Word, then Outlook, or msaccess, shows the problem.

----
start /b cmd /c "C:\Program Files\Microsoft Office\Office\Winword"
start /b cmd /c "C:\Program Files\Microsoft Office\Office\msaccess"
----

Comment
Watch Question

Commented:
Try start /separate /b cmd /c . . .

Commented:
put the word "exit" at the end of your batch file

Author

Commented:
Nope - neither /separate or the exit at the end make any difference.
The DOS window sits there until the last App is closed.

(I can't find a reference to /separate in win2k scripting?)

Commented:
Why use cmd to start the application.

start winword
start msaccess

I just used this simple batch file and it worked just fine.

Author

Commented:
Kitekid,
  thanks, but unfortunately you missed the point.
My script "updates a few things, then starts several programs".
You aren't going to have any of the programs I run, so I showed an example with common progs like Word as a way to replicate the problem.
If you run any program with a full path, as shown in my example, the DOS box hangs around.
In that case also, "Start" without the other parameters, causes yet another DOS box for every start.

At this stage, if there is no apparent way to get around it with standard functionality, I will resort to a one line VB program that will launch the script as a Hidden process. That does what I want, but it bugs me that MS broke what works well in Win9x

Commented:
start the programs with "start" (as earlier mentioned here) just to make sure they run in their own process.

Check this, by adding an echo line or something to the script so that you can ensure yourself taht the programs start, but your script is still executing.

When that works as it should, add an CLS at the end of the script, this will automatically close your dos box.

Author

Commented:
I'll check it out when I get back from holidays (mid summer down this end of the world)
have a pleasant Christmas.....

Commented:
What you have found is, in my opinion, bug #19546 in the always growing list of oddities, bugs and flaws in the Windows 2000 operating system.

Try this, this batch works like intended:

start d:\Progra~1\Micros~2\Office\Winword.exe
start d:\Progra~1\Micros~2\Office\excel.exe
start %windir%\system32\notepad.exe

Use dir /y to find the short names of your directories.

Works like you wanted: starts all three programs, and then terminates, while leaving all three open. Eliminating the start command will make the batch wait until the program is closed. That's the way it should be ...

The problem seems to be that start <just the command> fails becuase of the whitespace character in "program files" and "Microsoft Office", and the ordinary NT way to enclose the command in "" makes the start command to start just an empty command interpreter, which is what I clearly claim to be a bug, unless someone shows me what that "feature" is supposed to be good for, and where it was documented, and what alternative character can be used to quote commands that have whitespace characters in their path.

Now using the short path names may or may not be an option for you. Despite that they look odd, and may be turned off by system setting, you cannot always rely on the fact that "Microsoft Office" is "micros~2", this depends on wether there are other directories that abbreviate to Micros~something, and the order they were created in. Even a Backup/Restore of a directory may flipflop the ~ names.

Armin Linder

Commented:
Armin,

The "" is to specify a Window title, eg:

start "I like this window title thingie" "C:\Winnt\System32\Notepad.exe"

offcourse this title will never be used in Notepad, but for cmd.exe windows it can be used, eg:

Start "Please wait while configuring your network settings" "C:\Winnt\system32\cmd.exe"

groeten

Commented:
Thats it! Tada!

If you use

start "" "d:\program files\microsoft office\office\winword.exe"
start "" "d:\program files\microsoft office\office\excel.exe"

the batch file does work like intended. What a command line parameter parser design, really. So #19146 is category: oddity.

Armin Linder

Commented:
Thats it! Tada!

If you use

start "" "d:\program files\microsoft office\office\winword.exe"
start "" "d:\program files\microsoft office\office\excel.exe"

the batch file does work like intended. What a command line parameter parser design, really. So #19146 is category: oddity.

Armin Linder

Author

Commented:
Hey Armin, great, that seems to do the trick!
thanks folks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.