View Full Version : batch files again

25-02-2004, 11:26 PM
Hi, just wondering, how do you write a command in a batch file to terminate/close a program?

eg: close windows media player while its running?


25-02-2004, 11:47 PM
is this what you are looking for

25-02-2004, 11:52 PM
or this one
ok the reference file then
I think these comands will only work on nt based kernal operating systems ie nt,win2k,xp home and pro

26-02-2004, 12:04 AM
just a note of caution here
read those instructions carefully especially the footnotes

26-02-2004, 12:15 AM
hello beama.

unless i dont know how to use the command correctly, or if i have misunderstood what is in the website that u have given, i dont think its really what is what im looking for :(

anyway.... let me make it more clear, cos i think wht i posted was actually very slack, and i dont even know if it can be done. :-\

ok, imagine this, i have wrote a very simple batch file lets just say i want to play a video file, (just with this command: video.avi).

lets say the avi file was play using the default windows media player program, and after the file finish playing, it just stay there. the program dont actually go away unless u manually close it.

so, what i want to do is, i want to add a command in the batch file that will actually close the program (win media player) for me as well instead of just lay there after it finish playing.

so, i dont know if there is such a thing. so, if the kill command is the right command for it, then probally i just dont know how to use it correctly, so can u please write it out exaclty for me :)

btw, running winxp pro

26-02-2004, 07:25 AM
interesting, sounds possible but I have never done it so ill do some expermenting, in the mean time I think the person you need is Parry he is a wiz with batch files lets hope he reads this thread and is able to help
watch this thread
at this satge I think you will need to pause/ delay the batch file while media player completes its task then issue the kill comand then i suppose because you are in bed asleep by now your what your pc to be shutdown from the batch fie, i know this is possible(what next remote controls for tv's :) )

Graham L
26-02-2004, 01:19 PM
Batch system is a primitive, limited, scripting system.

Try getting a command window,and seeing if there are any options for the media player. If it can be started from batch, it "ought" to have an option which will tell it to run then exit.

You will need to discover the name of the executable, then something like nameofmediaplayer.exe /? might tell you want you need.

If there's something appropriate you would then invoke it, giving the name of the file to be played as an argument, and the option which tells it to exit.(e.g. nameofmediaplayer.exe /x /f=video.avi).

26-02-2004, 03:43 PM
Check out media player classic, it supports a command line interface and can even return an error level!!

26-02-2004, 11:10 PM
Yes Graham I would agree, but I do believe they can still be useful, in this case they are very limited I would considered using a vbs script file, but he asked for a batch file and here is what I have come up with.
It needs windows scheduler because I know of no way a batch file can monitor a process or thread to see if it active, so scheduler will need to set up to run this batch file at a certain time

Batch File

@echo off
rem ************************************************** ************

rem This batch file will shutdown the media player process
rem and log off windows session. Tested on Xp Pro
rem Use windows scheduler to run this batch file at specified time

rem ************************************************** ************

rem kill process wmplayer.exe
rem for more help on tskill type "tskill/?" at cmd prompt

tskill wmplayer

rem log off windows session
rem for more help with shutdown type "shutdown/?" at cmd prompt

shutdown -l

27-02-2004, 01:20 AM
Thank you beama :)
it is what im looking for, I will do other experiments from there.

Graham L
27-02-2004, 10:49 AM
I wasn't "criticizing" DOS, just making the comment. ;-) I used to avoid trying cleverness in DOS because it is so easy to write programmes in Turbo Pascal to do such things.

I had a look at Windows media Player last night, and found that although you can start it from DOS, you can't pass any options. :_| But the "/?" option to a call is always the first step when investigating programme bevaviour. (I've even used the *nix strings programme to look for undocumented options, at times).