How to prevent multiple launch of a program from Explorer window ?

Mar 4, 2020
38
0
Hello.
It appears that programs still launches twice because while the *.btm file is running the second copy launches as well. So, how to detect running *.btm file ?

thanks
 
Mar 4, 2020
38
0
Any program or one program? Any BTM or one BTM (what does it do?)? Steps to reproduce the error.
One BTM - which checks if another copy of itself is running.

There is no error - the first copy of BTM (As per advice above) works fine but the second works fine as well and each starts the relevant program (MSAccess). This is because execution of BTM takes more time than for OS to launch the second copy of the BTM file. I know that I can adjust the mouse settings, but do not want to do this yet.
 
May 20, 2008
12,167
133
Syracuse, NY, USA
Your post #31 appeared at the top of page 2. I thought it was the beginning of this thread. I apologize for that.

How about using a "sentinel" file in %TEMP to tell the BTM that it is already running? That should be faster than testing whether the app is running. This, below, works if I double-click the shortcut twice as fast as I can. Winword is only run once.

Code:
REM NOTTWICE.BTM
if exist %temp\not_twice_sentinel.txt quit
touch /q /c %temp\not_twice_sentinel.txt
start /wait winword
REM do other things when winword terminates
del /q %temp\not_twice_sentinel.txt
 
May 20, 2008
12,167
133
Syracuse, NY, USA
Apparently you can use a user environment variable as a sentinel. This works.

Code:
REM NOTTWICE.BTM
if defined not_twice_sentinel exit
set /u not_twice_sentinel=1
start /wait winword
REM do other stuff when winword terminates
unset /u not_twice_sentinel

My BTM association uses "/c".

Code:
v:\> ftype tcc.batch
tcc.batch="D:\tc28\tcc.exe" /c "%1" %*

And my shortcut looks like this.

1670524538993.png
 
Last edited:

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,689
106
Albuquerque, NM
prospero.unm.edu
Apparently you can use a user environment variable as a sentinel. This works.

Code:
REM NOTTWICE.BTM
if defined not_twice_sentinel exit
set /u not_twice_sentinel=1
start /wait winword
REM do other stuff when winword terminates
unset /u not_twice_sentinel

Maybe add a window hide before the start ?
 
Hey @vefatica,
What about using the Window Title as a sentinel?
Code:
@setlocal
@echo off
if defined titleprompt unset titleprompt
set theTitle=Working...
echo @winpid  : %@winpid[%theTitle]
iff %@winpid[%theTitle] gt 0 then
  echo A window with this title already exists.
else
  echo This .BTM is running in a window with a unique window title.
  title %theTitle
endiff
pause
title Ready.
endlocal

Joe

EDIT: I see that this has been done previously.
 
Last edited:
May 20, 2008
12,167
133
Syracuse, NY, USA
Hey @vefatica,
What about using the Window Title as a sentinel?
Code:
@setlocal
@echo off
if defined titleprompt unset titleprompt
set theTitle=Working...
echo @winpid  : %@winpid[%theTitle]
iff %@winpid[%theTitle] gt 0 then
  echo A window with this title already exists.
else
  echo This .BTM is running in a window with a unique window title.
  title %theTitle
endiff
pause
title Ready.
endlocal

Joe

EDIT: I see that this has been done previously.
That seems to work. I don't understand why unsetting TITLEPROMPT matters (it does). When started from a shortcut, there are no prompts involved and I thought TITLEPROMPT was only used when a prompt was issued.
 
Mar 4, 2020
38
0
I'm having some trouble with the user environment approach. I suggest you use the temp file as I suggested first.
Thanks for the idea. I should have thought about this myself as I've used this long time ago (are they also call flags ?). I also thought that using variable could be problematic as I do not fully understand where which variables are stored - does each shortcut runs its onw environment, etc.

BTW You use exit and quit (and both work) - but which approach is right ?
 
Last edited:

Similar threads