Jump to content

batch file (.bat's) exit command


cyberthug

Recommended Posts

hey.. is there anyway to get the batch files which are run at teh end of setup to exit using the 'exit' command as it works in XP?

so that it doesn't just show "FINISHED..." on the title, but closes the batch screen...?

thanx.

tried a few things.. but no luck.. maybe use of a "kill.exe" ? anyone use this?

another question... i think i saw this being mentioned, but search turned up with nothing..:(

my batch file keeps on looping, after i close it, it'll start again. it went out of the loop only when i closed the command box before installation was completed.. any idea's on what's up? (no.. i batch file isn't calling it self! lol)

Link to comment
Share on other sites


I got this trick from another member in this forum:

In Windows right click the batch file and select Properties. On one tab (I think it is the last one) there is an option to close the dos box on exit.

Once you did this a pif file with the same name as the batch file will be created. Copy these 2 files to your unattended folder.

Also I have an empty line after the last command in each batch file. You might to try this, too.

You can test it in Windows by double clicking.

Link to comment
Share on other sites

I don't know why your batch-file is calling itself repeatedly - if you used the code I previously gave, as it is it works fine.

Now for a "kill" command to enable us to have it done automatically (instead of having to close the command window manually). It seems that the win98 resource-kit itself has the required function.

For windows98 (at least), tlist.exe and kill.exe are available from MS:

(tlist gets you all the pids running)

ftp://ftp.microsoft.com/services/technet/...eskit/diagnose/

There's 2 problems with the above:

one, the reskit download address doesn't seem to work anymore. :blink:

two, using the kill.exe from the reskit, will require you to specify the ProcessID - which might vary everytime.

So if you want to kill the process name instead, save the below code as killer.vbs (or whatever) and run it just before the "EXIT" command.

' Killer.VBS
' This script kills all processes with name COMMAND.COM

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
   ("SELECT * FROM Win32_Process WHERE Name = 'command.com'")
For Each objProcess in colProcessList
   objProcess.Terminate()
Next

You can run it with the command:

cscript.exe //B %windir%\killer.vbs

And how to copy killer.vbs to %windir% in the first place? Put the file in your cabs folder, and add the file-name to the list of files to copy, in MSBATCH.INF.

Link to comment
Share on other sites

Wireless - thankyou, thankyou, thankyou! That issue's been jacking me off for ages! The only downside to use of exit (in redistributable scripts only of course) is that there's no easy way (that I know of) to establish how the batch file was started. If it's started via "Windows" methods all is good and well but if executed via a DOSbox commandline 'exit' can be a rather rude way to end a batch file. I found the same applied with AmigaDOS - lots of scripts being written using 'endcli' to handle the same problem (shortcuts had no "close on exit"), all assuming that they were started via the GUI rather than from a commandline. Anyhows... thankyou, thankyou,... :thumbup

Link to comment
Share on other sites

  • 1 month later...

Err... nil, CLS stands for clear screen. It has nothing to do with exiting the batch file. I don't know some people have this problem but it must be the way the batch file is called cause all the batch files I've ever written exit unless you stick the PAUSE command in.

One way to stop this happening if say you wanted to call it automatically (and have close) and manually and keep the screen would be something like this. If the batch file you want to run is called DOSTUFF.BAT then wrap it up in another batch file to do the pause like so:

WAIT.BAT

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

CALL DOSTUFF.BAT

PAUSE

Then you can call DOSTUFF.BAT directly this will not wait or call it by calling WAIT.BAT. If you don't include CALL in WAIT.BAT then DOSTUFF.BAT will not return back to WAIT.BAT and so it won't do the pause.

Hope this helps.

Link to comment
Share on other sites

  • 7 months later...

Hi,

Confirmed WORKS with

cls
exit

On Windows98 the command window close itself, and works too with xp/2k ... so it's more easy to make a compatible unattended install ...

Goodbye.

edit: yes "cls" is for cleaning the screen but the method works so just Microsoft can make this :blink:

Edited by sonic
Link to comment
Share on other sites

Err... nil, CLS stands for clear screen. It has nothing to do with exiting the batch file.

Pedantically, you're right. CLS has nothing to do with exiting a batch file. And neither does EXIT (which is designed to end a command-line shell, not batch processes). None of which helps explain why your presumptions are flawed. :)

The issue being refered to was the closing of the console window which remains open, in some cases, after a batch process ends. That issue is caused by the use of any command which sends output to the console device and the solution to the problem does involve the use of CLS (and not EXIT - see below). Your disbelief is understandable (it certainly isn't a logical solution) but I can tell you it sure does work.

You can test it for yourself by creating a batch file with the following lines on the desktop and double-clicking the file:

@echo off
pause

When the batch process ends the console window remains open (on all Win9x systems that I've tested it on at least) and needs to be closed manually. Now edit the file to read as follows:

@echo off
pause>nul

As no output is sent to the console (PAUSE's output is redirected to the "nul" device) you should find that the window will close automagically when the batch file ends (which won't happen in this case if you forget to press any key...).

The how and why is beyond me but getting the window to auto-close after one or more commands have output to the console seems to require the use of CLS, eg:

@echo off
pause
cls

See, I told ya CLS stands for CLose Sceen! :P

The CLS needn't be at the end of the file by the way, just ensure no command sends output to the console after the CLS is issued. The following example batch file will also auto-close:

@echo off
pause
cls
::
dir>nul
::

Note that the use of EXIT in a batch file appears to be absolutely unnecessary for the purpose of auto-closing an orphan console window (and needn't be prepended with a '@' if it is used within a batch file as the command produces no output).

Again, the intended purpose of EXIT is to close the commandline shell it is issued from, and while it can be used to "exit" a batch file it's a rather crude (and arrogant) way of handling it (on someone else's system). Batch file execution ends when the command line interpreter reaches the end of the file so for a far more user friendly approach (and to stop us DOSbox users chucking cold pricklies at you) try using GOTO instead:

@echo off
...
goto:end
...
:end
cls

Anyhow I would be interested in hearing of any case where the CLS/EXIT combination (rather than CLS alone) is actually required.

Cheers.

Edited by nil
Link to comment
Share on other sites

Off topic:

Hi Sonic. It was meant as nothing more than friendly humour (I was essentially poking fun at myself for being a "hippy" in public :)) though I obviously need to work on my delivery style... :(

The terms "warm fuzzy" and "cold prickly" were coined by the famed psychologist Claude Steiner (born in Paris coincidently) and can be found within his childrens fable "A Warm Fuzzy Tale". (A french translation of the complete story can be found at http://www.claudesteiner.com/fuzzyfr.htm; see http://www.claudesteiner.com/fuzzy.htm for the english version.)

Some excerpts from the story:

Chaque enfant, à sa naissance, recevait un sac plein de chaudouxdoux. Je ne peux pas dire combien il y en avait car on ne pouvait pas les compter. Ils étaient inépuisables. Lorsqu'une personne mettait la main dans son sac, elle trouvait toujours un chaudouxdoux. Les chaudouxdoux étaient très appréciés. Chaque fois que quelqu'un en recevait un, il se sentait chaud et doux de partout. Ceux qui n'en avaient pas régulièrement finissaient par attraper mal au dos, puis ils se ratatinaient, parfois même ils en mouraient.
...
Elle distribua à chacun un sac qui ressemblait beaucoup à un sac de chaudouxdoux, sauf qu'il était froid, alors que celui qui contenait les chaudouxdoux était chaud. Dans ces sacs, Belzépha avait mis des froids-piquants. Ces froids-piquants ne rendaient pas ceux qui les recevaient chauds et doux, mais plutôt froids et hargneux. Cependant, c'était mieux que rien. Ils empêchaient les gens de se ratatiner.

A partir de ce moment-là, lorsque quelqu'un disait: "Je voudrais un chaudouxdoux", ceux qui craignaient d'épuiser leur réserve répondaient: "Je ne peux pas vous donner un chaudouxdoux, mais voulez-vous un froid-piquant?"
...

In writing "to stop us DOSbox users chucking cold pricklies at you" I simply meant that DOSbox users might not appreciate batch file coders using EXIT to kill a batch process (which is little different to writing an executable that shut down the Windows GUI when the program ended). Anyhow, while I imagined the meaning of what I wrote would be understood well enough I did wonder if only peacenik dinasaurs like myself knew what the term "cold pricky" refered to, and that's what was going through my mind when I replied to your "no post" post.

Again, no offense meant. And warm fuzzies to you my friend. :hello:

Edit: I hope the following isn't misconstrued but I found it way too funny to keep to myself. I just emailed a friend about the above and her deadpan reply was "Maybe he thought you were ragging him with hedgehog jokes :*|" (obviously refering to that very cool and definately prickly computer game character "Sonic the Hedgehog"). ROTFL! Cheers again.

Edited by nil
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...