Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

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

Hello

I run begin.btm by double-clicking it from an Explorer window. It launches

-----------Code.btm-----------
MSACCESS.EXE test.mdb
bsa.bat
-------------

Often my computer freezes/I click too much and it launches multiple copies of begin.btm/Code.btm/MSACCESS.EXE. How to prevent this/best way to check if Code.btm or internal commands are already running ?

thanks
 
Have you tried it from the console ?

or

iff "%@word[3,%@execstr[tasklist /zu msaccess*]]" == "" then
msaccess.exe test.mdb
call bsa.bat
else
echo Already Running!
endiff
 
There is also IF ISAPP.

But if inadvertent double-clicking is a frequent problem, it might make more sense to adjust the double-click speed in the 'Mouse' control panel.
 
Thanks. I lauch it as an icon from desktop.
I tried:

----------
IF ISAPP "C:\Office2003\office11\MSACCESS.EXE" (quit) ELSE (detach msaccess.btm)
---------

and it seems to work !
 
1) After using it for a while it turned out that quite often the window with the command below does not close while MSACCESS.EXE works - that black window remains in the list of open windows. And probably as the result this does not prevent the double launch of MSACCESS.EXE. To be clear: I have only one icon on the desktop which can launch MSACCESS.EXE, i.e. only via launching

--------------------MSACCESS.btm-----------------
IF ISAPP "C:\Office2003\office11\MSACCESS.EXE" (quit) ELSE (detach msaccess.btm)
------------------------------------------------------------

2) I also tried the second suggested approach:

--------------------MSACCESS-version2.btm-----------------
echo off
iff "%@word[3,%@execstr[tasklist /zu msaccess*]]" == "" then
call msaccess.btm
else
echo Already Running!
pause
endiff
------------------------------------------------------------
It does not launch MSACCESS.EXE and show the "Already Running!" message while MSACCESS.EXE is not running





Any ideas how to fix this behaviour ?
 
How are you starting MSACCESS.btm? If you're starting it from Explorer or a shortcut which targets the BTM, and have used TCCHERE.BTM to install the shell command, then the instance of TCC which runs the BTM is expected to hang around. Below is a line from TCCHERE.BTM. The "/k" means don't exit after running the BTM.

Code:
echo %@regset["HKCR\Directory\Shell\TCC\command\",REG_SZ,"%_cmdspec" /k *cdd "%%L"] > nul

Charles's suggestion (add an "EXIT") will take care of that. To change the behavior for all BTMs, change the "/k" to "/c" in both these places.

Code:
HKCR\Directory\Shell\TCC\command\
HKCR\Drive\Shell\TCC\command\
 
How are you starting MSACCESS.btm? If you're starting it from Explorer or a shortcut which targets the BTM, and have used TCCHERE.BTM to install the shell command, then the instance of TCC which runs the BTM is expected to hang around. Below is a line from TCCHERE.BTM. The "/k" means don't exit after running the BTM.

Code:
echo %@regset["HKCR\Directory\Shell\TCC\command\",REG_SZ,"%_cmdspec" /k *cdd "%%L"] > nul

Charles's suggestion (add an "EXIT") will take care of that. To change the behavior for all BTMs, change the "/k" to "/c" in both these places.

Code:
HKCR\Directory\Shell\TCC\command\
HKCR\Drive\Shell\TCC\command\
I start MSACCESS.btm from shortcut which targets the BTM. The important bit is that sometimes I have that effect and sometimes I don't. From what you say it should be one consistent result - correct ?
I don't have these registry entries in Win7, even HKCR...
 
I think it should be consistent.

My mistake, I should have referred you to

Code:
HKEY_CLASSES_ROOT\TCC.Batch\Shell\Open\Command

[I got it confused with the "TCCHere" mechanism.]

You could also put the "/c" in the shortcut itself ... target: [path]\tcc.exe /c [path]\msaccess.btm
 
Hmmm! My HKEY_CLASSES_ROOT\TCC.Batch\Shell\Open\Command entry has "/c" in it.
 
I think it should be consistent.

My mistake, I should have referred you to

Code:
HKEY_CLASSES_ROOT\TCC.Batch\Shell\Open\Command

[I got it confused with the "TCCHere" mechanism.]

You could also put the "/c" in the shortcut itself ... target: [path]\tcc.exe /c [path]\msaccess.btm
My existing registry entry was ""C:\TCMD\TCC.EXE" /c "%1" %*" - so the problem was not with "/k"


So far "Exit" seem to work and I just need to test everything for few weeks to see if it is consistent
 
I think your BTM should be using START "C:\Office2003\office11\MSACCESS.EXE". If you just call the EXE by name, the BTM will wait for it to terminate.
 
I think you could boil it down to just:

Code:
if not isapp msaccess.exe start /pgm "c:\office2003\office11\msaccess.exe"
exit

No need for two batch files, or DETACH. (I'm sure DETACH must be very useful for something, but I've never figured out what.)
 
In fact, on second thought, I'll bet you could eliminate the EXIT. The leftover console window is probably the one created by DETACH.
 
1) After using it for a while it turned out that quite often the window with the command below does not close while MSACCESS.EXE works - that black window remains in the list of open windows. And probably as the result this does not prevent the double launch of MSACCESS.EXE. To be clear: I have only one icon on the desktop which can launch MSACCESS.EXE, i.e. only via launching

--------------------MSACCESS.btm-----------------
IF ISAPP "C:\Office2003\office11\MSACCESS.EXE" (quit) ELSE (detach msaccess.btm)
------------------------------------------------------------

2) I also tried the second suggested approach:

--------------------MSACCESS-version2.btm-----------------
echo off
iff "%@word[3,%@execstr[tasklist /zu msaccess*]]" == "" then
call msaccess.btm
else
echo Already Running!
pause
endiff
------------------------------------------------------------
It does not launch MSACCESS.EXE and show the "Already Running!" message while MSACCESS.EXE is not running

Any ideas how to fix this behaviour ?
Hmmm I don't understand, tasklist report's ALL running programs. So when it detects its name MSACCESS.EXE it is by all means loaded. That's all tasklist is showing so the btm is showing that.
 
Last edited:
I think your BTM should be using START "C:\Office2003\office11\MSACCESS.EXE". If you just call the EXE by name, the BTM will wait for it to terminate.
Actually it was the full path and I've changed it just on the day I've decided to resume my questions here.



------Now it turned out that Exit does not help. I just had the same unclosed window in case of

-----------start-word.btm----------------------------
IF ISAPP winword.exe (quit) ELSE winword.exe
exit
----------------------------
Then I've closed everything and added full path - the situation repreated (may be it was provoked by first launch without the full path ?).
 
Last edited:
In fact, on second thought, I'll bet you could eliminate the EXIT. The leftover console window is probably the one created by DETACH.
I like the idea of "if not" as the code is more robust. But after launching the relevant program, when I close it, I would like to launch another bat file which will archive the relevant files (and I don't want to see any waiting windows like for Start while working in the program). So detach was probably for that purpose.


I've tried the

---------------word-lauch.btm---------------
if not isapp "c:\office2003\office11\winword.exe" "c:\office2003\office11\winword.exe"
exit
----------------------------------------------------
and the problem is still there
 
Last edited:
I've tried the

---------------word-lauch.btm---------------
if not isapp "c:\office2003\office11\winword.exe" "c:\office2003\office11\winword.exe"
exit
----------------------------------------------------
and the problem is still there

You need a START /PGM in there:

Code:
if not isapp winword.exe start /pgm "c:\office2003\office11\winword.exe"
 
You need a START /PGM in there:

Code:
if not isapp winword.exe start /pgm "c:\office2003\office11\winword.exe"
I don't understand what benefit Start gives unless I use any special option like /wait. I also did not understand the meaning of /pgm as per the Help file - if it comes before a program name, then how it is different from specifying just the program name... Will try to test it tomorrow.
 
I also did not understand the meaning of /pgm as per the Help file - if it comes before a program name, then how it is different from specifying just the program name
By default START's first quoted argument is assumed to be a title. If you don't want to specify a title but want to quote the program name, use /pgm.
 
Start generates open waiting window in the task list which is unconvinient.

I understand why Exit does not work - I do not see it executed in the black TCC window command prompt. Only the first line of the code launching relevant program. Apparently TCC waits for that programs to terminate before it execute next line of code..
 
Last edited:
Sergey, can you please start from the beginning and say EXACTLY what you want to happen after initiating things with a double-click on a shortcut. I'd like to help more but I've lost track of what you want to do.
 
Sergey, can you please start from the beginning and say EXACTLY what you want to happen after initiating things with a double-click on a shortcut. I'd like to help more but I've lost track of what you want to do.
I want to prevent accidental double-clicking/double launching of various programs and also would like to launch specific bat file after the program finishes - but without having waiting TCC black window in the tasklist.
 
TaskManager, i.e. list of open programs when I switch between them by alt-tab
If you want TCC to launch a specific batch file after the app closes then TCC must wait (continue running). It's impossible to avoid seeing it in TaskMgr. The following method will keep it from appearing in the task switcher (Alt-Tab) and otherwise minimize the visual impact.

1. Write a BTM that starts the app if it isn't already running ... something simple ... perhaps like this (MSACCESS.BTM).

Code:
if isapp MSACCESS.EXE exit
"C:\Office2003\office11\MSACCESS.EXE"
REM the BTM will wait for MSACCESS.EXE to terminate
REM Do your other stuff here
exit

2. Make a shortcut with target

Code:
[path]\TCC.EXE /C start /INV /C [path]\MSACCESS.BTM

and configure the shortcut to run minimized.

You won't see the console of the TCC started by the shortcut because it's minimized; that TCC will exit immediately after starting your batch file in an invisible TCC.

The invisible TCC running the batch file will exit immediately if MSACCESS.EXE is running. If MSACCESS is not running, the batch file will start it, wait for it to finish, and run your other commands. The invisible TCC won't show up in the task switcher. It will be in TaskMgr (ALL processes show in TaskMgr).
 

Similar threads

Back
Top