1.

Solve : Test to see if Batch File is running?

Answer»

Oh, I was thinking to see if there are to sessions of cmd.exe running. Maybe the batch file could create a file when it starts, and delete it when it completes.

The batch file could then check for the existence of that file when it starts, and if it finds the file, it would exit, or else it would carry on.
That would be a lot of work. Because the only way that you could really quit would to click the exit button in the corner of the SCREEN. Or doing quit. But the person will probably press the X button. Quote from: BatchFileCommand on March 02, 2009, 07:25:47 PM

the only way that you could really quit would to click the exit button in the corner of the screen. Or doing quit.

A batch file will quit when it encounters the EXIT command. I may have misunderstood your requirements, but what I was thinking of was something like this:


@ECHO Off
:: Check if temporary file exists
If Exist %temp%\AlreadyRunning.tmp (
Echo This batch file is already running & Goto :EOF)
:: Else create it
Echo . > %temp%\AlreadyRunning.tmp
:: Carry on with remainder of batch file
Echo.
Echo Do whatever here, then
Echo.
:: Delete temporary file
Del %temp%\AlreadyRunning.tmp

My program. Doesn't really have a beginning and an end. It has a old GUI with options.Quote from: BatchFileCommand on March 03, 2009, 07:57:08 PM
My program. Doesn't really have a beginning and an end. It has a old GUI with options.

all programs have a beginning and an end. instead of exiting the batch file using EXIT, you can REDIRECT to a label that performs the necessary cleanup.Even if it does have a beginning and an end. What if someone doesn't know about the file and clicks the X button in the corner of the screen. Then they would NEVER be able to use it again. This is why I stopped using this method in my batch files/programs early on.


Discussion

No Comment Found