Solved

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

Posted on 2003-10-21
9
1,826 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

687 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