简体   繁体   中英

Executing a command when closing Batch file

I have a batch file playing a sound in the background while it runs, using the method at Batch file executing a sound silently however, when I exit the batch file, the music will continue to play.

Id there any way to run a command while a batch file is closing, so that the sound file will stop playing?

I've tried an example I found called onexit:

onexit taskkill /im wmplayer.exe

But it doesn't work.

Just :

taskkill /f /im wmplayer.exe

Should work.

First idea i had is another batch:

@ECHO OFF
START "" /W <YourBatchhere>
TASKKILL /im "wmplayer.exe"

should do the job :)

The /W will wait at that point, still YourBatchhere has ended. Regardless of success or error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM