Link to home
Create AccountLog in
Avatar of Zack
ZackFlag for Australia

asked on

Prevent a program running two instances of itself via BATCH

Hi EE,

I have the following batch script:

start "" "C:\eBroadcaster\EBroadcaster1.exe" -S"ASDFSQL";-D"MAILman_PROD";START

Open in new window


How do I get the batch to search for another instance 'EBroadcaster1.exe' and to terminate if finds one currently running, to prevent the program from running two instances of itself?

Any help is welcome.

Thank you.
Avatar of Dr. Klahn
Dr. Klahn

When the program starts:

Check for the existence of "flagfile.txt" in a directory to which it has write access.  If it finds the file, exit.

Create the file.  No content is necessary; the existence of the file is the flag.

When done processing, delete the file in the closing cleanup code.

This is crude but easy to implement.  The problem is that if the program is aborted or terminates abnormally, the flag file remains unless the program catches the abort command and deletes the flag file in the abort handling code.
ASKER CERTIFIED SOLUTION
Avatar of mbkitmgr
mbkitmgr
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Zack

ASKER

Hi mbkitmgr,

Thank you very much for your help much appreciated.

Cheers.