Solved

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

Posted on 2003-10-21
9
1,814 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Join & Write a Comment

Several part series to implement Internet Explorer 11 Enterprise Mode
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now