Solved

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

Posted on 2003-10-21
9
1,825 Views
Last Modified: 2013-12-29
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
0
Comment
Question by:happycat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 49

Expert Comment

by:sunray_2003
ID: 9596076
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
0
 

Author Comment

by:happycat
ID: 9596166
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?

0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 9596197
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:CrazyOne
ID: 9596242
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.
0
 

Author Comment

by:happycat
ID: 9596446
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

0
 
LVL 1

Expert Comment

by:Egoslayer1
ID: 9610322
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.
0
 
LVL 1

Expert Comment

by:Egoslayer1
ID: 9610409
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
0
 

Author Comment

by:happycat
ID: 9611865
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
0
 
LVL 1

Accepted Solution

by:
Egoslayer1 earned 300 total points
ID: 9739244
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question