How to close a program using a batch file? Time delay too?

Hi.

I have a batch file that starts a program
in Win 98SE.

Now, how can I make the batch file close
this program?

More exact...how can I make the batch file
close this program after "x" amount of time?

If not possible, can I use some basic scripting
to achieve this, if so how?

Thanks a bunch,

Tim
happycatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunray_2003Commented:
Tim,

Check this

http://www.experts-exchange.com/Operating_Systems/WinXP/Q_20720235.html

Try to use other options of the command to get time delayed closing

Sunray
happycatAuthor Commented:
Thanks. However both TSKILL Command and TASKKILL are not recognized commands on my system (Win 98SE)

Is there a way to upgrade the commands recognized or am
I limited to what Win 98SE has for DOS commands?

CrazyOneCommented:
Well there isn't any thing like a resource kit for Win98 like there is for NT and up. Quite frankly I don't think you can do it through a batch file I beleive you would need to use VB scripting or develop an actual program to do it.
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

CrazyOneCommented:
Programically I do things like this to close a program.

Example to close the MS heart program I know the title of the window is "The Microsoft Hearts Network"

so I do this
SendMessage(FindWindow('The Microsoft Hearts Network', nil), WM_CLOSE, 0, 0);


If you know that class name of the window then you can us it to do the same thing. In this case I know the class name is "AfxFrameOrView42u:

so I do this
SendMessage(FindWindow('AfxFrameOrView42u', nil), WM_CLOSE, 0, 0);


These examples are from my Windows XP but the idea is the same.
happycatAuthor Commented:
Thanks All.

I just figured out a way to do this in Win98.

There is a freeware "Process Viewer"
for Windows NT/2000/XP and 95/98/Me at:

http://prcview.com  or
http://www.xmlsp.com/pview/prcview.htm
http://www.xmlsp.com/pview/PrcView.zip

or

http://www.teamcti.com/pview/
http://www.teamcti.com/pview/PrcView.zip

It's as simple as two lines in a batch file like this:

start pv.exe
pv -k exampleprogram.exe

where -k is to kill and if desired:

pv -kf exampleprogram.exe

where the f is for forcing the kill

I'll try to figure out ways to manipulate the timing as desired.

Is there a way I can repeat certain lines of a batch file
without retyping the same code?

...for example something to create a loop from one line through
another for "x" amount of times?

Anyway here is more of the info:

PrcView v 3.7.2.4 command line utility by Igor Nys
Usage: pv -[<MODE>] -[<OPTIONS>] <ARGUMENTS>...-[<OPTIONS>]

support@prcview.com
or contact directly at igornys@writeme.com

Egoslayer1Commented:
use 'for' command to repeate lines, FOR us weak in 98, but immensly powerful in NT and newer...still FOR can do a lot of things if you get creative, even under 98

use sleep to pause thing for a set number of seconds...sleep is standard on newer windows OS's, but you can find free versions on the internet for 98, if you can't locate them, email me at Egoslayer1@hotmail.com and I'll send you a copy.
Egoslayer1Commented:
you can also use IF to loop a section of batch file and break out after a fixed number or  time, or rather when a variable equals the right thing... something like

@echo off

set X=1
:start
echo %X%
if "%X%" EQU "20" goto end
set /A X=%X%+1
echo %x%
goto start

:end
echo done
pause

slight syntax aside, would repeat everythign between ":start" and "goto start" 20 times, which in this case is echo'ing the variable %X%.

IF will often get you what you need, but FOR is made specifically for that, and is thus frequently cleaner.

ES
happycatAuthor Commented:
Thanks Egoslayer1.

I'd like to give you the points since that was helpful for my second question, which I apologize for not making a seperate question
to have the topic stay focused.

So to have the answer for this question be
appropriate for people searching...

could you copy parts my previous post for closing progs in batch, with your other comments about FOR and IF, and by all means any other alternatives for closing progs in batch files.

Plus I also found a shareware utility called
"Hold!"

usage [hold!] [seconds] [option]
option c is to show countdown.

http://www.filelibrary.com/Contents/DOS/51/5.html
http://www.filelibrary.com:8080/cgi-bin/freedownload/DOS/h/51/hold!.zip

Works like a charm.

Also, another way to create loop (however infinite) is found here:

http://www.experts-exchange.com/Operating_Systems/Win98/Q_20774606.html
Egoslayer1Commented:
You can close a program in 98 with PrcView. I'm sure there are other programs out there to do the same thing. PrcView is neat since it works on most any windows version.

http://www.teamcti.com/pview/prcview.htm

also the aforementioned sleep program available for free from MS, it comes in some of the resource kits, the one for 2003 is here...
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

Sleep works just like the hold program you found, except sleep doesn't have a countdown option, so hold might be better.

ES

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.