Copyright © 2003-2010 by Prof.
Last modified Sun 2-May-2010 11:25:29
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
This page is edited from the 1cmdfaq.txt faq-file contained in
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
Please see "The Description and
the Index page
" for the conditions of usage and other such
2} On Windows XP how do you stop the script files from closing?
If one runs a .cmd script file by clicking the icon of the script,
the window will close after the processing is completed.
Occasionally this may not be what the user wants.
Method 1: To keep the window open to see the results one can use:
:: The body of the script with whatever task.
This will produce
Press any key to continue . . .
The window will then close when a key is pressed.
You also might notice that some of my scripts
included in this collection have the concluding line
if not defined cmdbox if defined PauseIfFromDesktop pause
The purpose of such a line is to prevent a script from immediately
closing on completion if called (clicked) from the desktop. This
allows you to view the results. However, this requires some special
- I have defined a PauseIfFromDesktop variable into my
- Right click: My Computer
- Choose Properties
- Choose Advanced
- Click "Environment Variables"
- For User variables click New
- Define PauseIfFromDesktop true
- See the "set cmdbox=true" spot in item #3.
Method 2: There is a more generic solution. Put as the very last
line of your script
The window will remain open as is (was) familiar from the Win3.x/95/98/Me
dosbox, and it will allow you to give further commands. To finally
close the window, type "exit". See
for utilizing the "cmd" line in customizing a command line window to
For more on the environment settings see