There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
blue screen blue screen of death boot computer connection cpu crash css dell display driver drivers email error ethernet excel firefox firefox 3 game hard drive hardware internet internet explorer itunes laptop malware monitor network networking nvidia outlook outlook 2003 outlook express partition printer problem problems router security slow software sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
MS-Dos Batch File Check if Program is running and exceute


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Boylett's Avatar
Computer Specs
Member with 49 posts.
 
Join Date: Dec 2006
Experience: Intermediate
23-Dec-2006, 06:21 PM #1
MS-Dos Batch File Check if Program is running and exceute
I have just started trying to do some code for MS-Dos Batch files. I have written a few minor things like, returning someones text they enter. But I have been searching all over google and I can't find out how to do this:

How can I make it so every 5 minutes, the MS-Dos Batch file will check if a .exe file is running, if it is, leave it and starting counting again, and, if it isnt, start it and start counting again.

Thanks

p.s. nice christmas smilies
Chicon's Avatar
Computer Specs
Distinguished Member with 6,681 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
24-Dec-2006, 09:09 AM #2
Hi Boylett,

Welcome to TSG !

You should first download the Windows 2003 Resource Kit from here.
There is a tool called pmon.exe that allows you to view the running processes in a DOS window.

Also, add a look to the MS-DOS at command to schedule tasks to be performed at a specified time and date.
__________________
Never teach an old monkey how to make faces. - (French maxim)
Boylett's Avatar
Computer Specs
Member with 49 posts.
 
Join Date: Dec 2006
Experience: Intermediate
24-Dec-2006, 09:34 AM #3
Ok, I have downloaded the Windows 2003 Tool Kit. When I looked at pmon.exe, yes it told me which programs were running, but how would I go about doing a command which asks it whether a program is running?
Chicon's Avatar
Computer Specs
Distinguished Member with 6,681 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
24-Dec-2006, 11:09 AM #4
Example :
-------

Code:
pmon.exe > result.txt
find "your_process.exe" result.txt
if errorlevel 0 goto found
...
...
...
:found
...
...
Boylett's Avatar
Computer Specs
Member with 49 posts.
 
Join Date: Dec 2006
Experience: Intermediate
24-Dec-2006, 12:20 PM #5
Its writes nothing to result.txt
Chicon's Avatar
Computer Specs
Distinguished Member with 6,681 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
24-Dec-2006, 02:05 PM #6
- Dowload Process Viewer for Windows from here,

- Extract the file into a folder anywhere on your drive,

- Browse the folder and you'll see a file called pv.exe,

- Via a DOS windows : cd until you reach the folder then type pv > result.txt and you will have all the running processes in the file result.txt (it works).

The pmon.exe is aimed to build a batch file, you must trigger to show the processes.

Also, you may copy paste the pv.exe file into the folder where the MS-DOS executables are stored (C:\WINDOWS\system32 if you've a standard installation of Windows XP).
__________________
Never teach an old monkey how to make faces. - (French maxim)

Last edited by Chicon : 24-Dec-2006 02:12 PM.
Boylett's Avatar
Computer Specs
Member with 49 posts.
 
Join Date: Dec 2006
Experience: Intermediate
24-Dec-2006, 05:24 PM #7
ok, still a few problems

Code:
@echo off

:BEGIN

cd G:\pv
START pv.exe

pv > result.txt

find "prog.exe" result.txt
if errorlevel 0 goto BEGIN

cd G:\

START prog.exe

goto BEGIN
if this line: if errorlevel 0 goto BEGIN is if errorlevel 1 goto BEGIN it constanly starts program, if its how it is, it never starts it. So its still not working >.<
Chicon's Avatar
Computer Specs
Distinguished Member with 6,681 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
25-Dec-2006, 03:48 PM #8
I have tested the following code and it works :

Code:

@ECHO off

:BEGIN

%SystemRoot%\Temp\pv.exe -d10000 > result.txt

FIND "notepad.exe" result.txt
IF ERRORLEVEL 1 %SystemRoot%\system32\notepad.exe

GOTO BEGIN
The -d10000 parameter of pv.exe means a delay of 10 seconds.
After the FIND command, the test of ERRORLEVEL must be retricted to the value 1.
Indeed, the value 0 is always produced weither the string was found or not !
__________________
Never teach an old monkey how to make faces. - (French maxim)
Boylett's Avatar
Computer Specs
Member with 49 posts.
 
Join Date: Dec 2006
Experience: Intermediate
25-Dec-2006, 07:44 PM #9
it writes nothing to result.txt, still, so constantly starts it for me ???
Chicon's Avatar
Computer Specs
Distinguished Member with 6,681 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
26-Dec-2006, 05:42 AM #10
Duh ! My previous code seems working but in fact, it's waiting the Notepad process to be closed. Also, the delay parameter of the process viewer doesn't produce any result.

Now, I assure you the following piece of code is working : this time, I've tested it step by step and the result.txt file is not empty :

Code:

@ECHO off

:BEGIN

%SystemRoot%\Temp\pv.exe -d10000

%SystemRoot%\Temp\pv.exe > result.txt

FIND "notepad.exe" result.txt
IF ERRORLEVEL 1 START %SystemRoot%\system32\notepad.exe

GOTO BEGIN
__________________
Never teach an old monkey how to make faces. - (French maxim)
Boylett's Avatar
Computer Specs
Member with 49 posts.
 
Join Date: Dec 2006
Experience: Intermediate
26-Dec-2006, 08:10 AM #11
Thanks, its all working now
Chicon's Avatar
Computer Specs
Distinguished Member with 6,681 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
26-Dec-2006, 08:54 AM #12
Quote:
Originally Posted by Boylett
Thanks, its all working now
You're welcome !
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:44 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.