It applies to the window from which the .btm was started.
Put the following code into a
.btm file,
for example,
test.btm
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.
:: We won't be running MS-ACCESS.EXE
else
echo This .BTM is running in a window with a unique window title.
title %theTitle
::Put the code that you want to run only once in this section of the iff
::For example, MS-ACCESS.EXE
pause Launching MS Access. Press any key to continue...
endiff
pause %_batchname complete. Press any key to continue...
title Ready.
endlocal
From Windows Explorer,
double-click on the
test.btm file to launch it.
On my system, this is what I get;
Now, from Windows Explorer,
double-click on the
test.btm to launch it again.
On my system, this is what I get;
The first run, the Window title is changed to
Working...
The second run,
we are told that a Window with the title
Working... already exists.
This is because there is already a Window called
Working...
No matter how many times you double-click on
test.btm,
it will not allow you to run a second instance,
as the Window with the title
Working...
already exists.
The Window title
Working... is unique.
What is even more unique is the process ID for the window with the specified title.
The process ID for the Window is unique.
That is, there can only be one process ID for the Window.
The
%@winpid[] is the variable
that I am using
to make sure that only one instance
of the
test.btm is run at one time.
Please give it a try,
and see if it does what you want.
Joe