The start command can launch an application like notepad in a batch file like this:
start notepad
start "my love.mp3"
But how do I close the running application from the command line? I found taskkill
in my searches but I don't think that is the right command because it's not working—it says no such file.
How do I close an application launched with start
?
Enter
taskkill /?
for the syntax and some examples. What you want to do is pass the/IM
argument using the name of the program you want to kill. For example:will kill notepad.exe.
will kill all processes beginning with "note".
Taskkill is correct. But you must kill the process playing the file, not the file itself. Figuring out the registered handler for mp3 files from a command prompt will be a bit tricky.
If you know it then you can kill that process.
Here's a script that figures out the registered application for mp3 files and kills the task:
If you save this as
killmp3.bat
or something, you can call it when you want. Of course be aware that if the program was already running, doing something else, that it will be closed anyway.Note that this depends heavily on the entry in the registry to have the executable path inside double quotes. If you don't have that and there are spaces in the executable name, it will fail.
You could generalize my technique to be able to pass in the file extension (such as
.mp3
, which you could look up in the registry to find the class namemp3file
and then find the handler from there.A more generic solution that takes the name of the file you started and figures out the extension from it is theoretically possible but a lot more difficult. In the case of
notepad
you have to figure out what that is by searching the path for all executable files, etc.This might be simpler if you created an extremely short mp3 file that you could start. Depending on the program, it might stop playing the current file and switch to the new one, which would end almost instantly and effectively stop playback.