Tech Support Guy banner
Status
Not open for further replies.
1 - 12 of 12 Posts

· Registered
Joined
·
55 Posts
Discussion Starter · #1 ·
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
 

· Registered
Joined
·
6,693 Posts
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.
 

· Registered
Joined
·
55 Posts
Discussion Starter · #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?
 

· Registered
Joined
·
6,693 Posts
Example :
-------

Code:
[SIZE=2]pmon.exe > result.txt
find "your_process.exe" result.txt
if errorlevel 0 goto found
...
...
...
:found
...
...[/SIZE]
 

· Registered
Joined
·
6,693 Posts
- 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).
 

· Registered
Joined
·
55 Posts
Discussion Starter · #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 >.<
 

· Registered
Joined
·
6,693 Posts
I have tested the following code and it works :

Code:
[SIZE=2]
@ECHO off

:BEGIN

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

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

GOTO BEGIN
[/SIZE]
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 !
 

· Registered
Joined
·
6,693 Posts
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. :eek:

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:
[SIZE=2]
@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
[/SIZE]
;)
 
1 - 12 of 12 Posts
Status
Not open for further replies.
Top