Make your own free website on
 Tips & Trix
Auto-Detect an already running instance of your Publication

Grafx Pax
Tips & Trix
Search NeoDezign


There may be times when you need to be able to detect if your program is running already if a user happens to try to run it a second time. Some programs will warn the user that they can only launch one instance of the program. Then exit gracefully.  While there is no built-in means to do this with NeoBook there is a solution.

The concept is simple really... 
Is the program running already?

True=Already Running
False=Not Running
Using the behavior of a NeoBook application in the way that it extracts files during runtime we can determine if an instance of the program exists.

A compiled NeoBook program will extract files only as they are requested. So, if a WAV file is played from the second page of your PUB it will only be extracted when that page is enacted by the user. If the first page does not play that WAV then, of course, the file will not be extracted.

We can take advantage of this behavior and use the first page to look for that sound file. If the file is not found then continue on into the publication because "Already Runnig=False". If the soundfile is found then "Already Running=TRUE".

The coding is easy. The key to making this all work is the choices made in the Compiler and making a decision as to where you will have your files extracted to. 

Let's assume for this example code and simplicity's sake that we will have the extracted files stored in the same directory as the publication. 

Create a new PUB with two pages. ("Page1" and "Page2")

In the "Page Action" for Page1 enter the following commands.

FileExists "[PubDir]soundfile.wav" "[alreadyrunning]"

If "[alreadyrunning]" "=" "True"
  AlertBox "Program Name" "You can only run one instance |of Program Name at a time"
  Exit "" ""
  GotoPage "Page2"

In the "Page Action" for Page2 enter this command

PlaySoundFile "soundfile.wav" "NORMAL"

Well... sorry to disappoint you but that's all there is to it!
Except for the Compiler...

Remember, the Compiler options are key to this procedure.

From the menu bar click "Book" > "Compile" and use the settings listed below.

  • General Tab
    • Application (EXE)
    • Compress Publication
  • Files Tab
    • Compile All Files Inside the Publication
  • Fonts
    • (your settings as needed)
  • Extracted Files
    • Same Directory as Compiled Publication
    • Remove Extracted Files when Publication Terminates
Press the Compile button.

After the compilation is complete use Windows Explorer copy the newly compiled program to a different folder. Do not copy the "soundfile.wav" file with it!

Run the program. It should run as normal and move to the second page where it will play "soundfile.wav". Look in the folder and it should be extracted there alongside your program executable.

Now, run it a second time. This time you should get the AlertBox from the second program. "You can only run one instance of Program Name at a time" After you press OK the second program should exit.

Lastly, go back to the first running program and close it while watching the extracted files disappear from Windows Explorer!

  • If your program requires that the extracted files be stored in the Windows Temporary folder simply use [TempDir] in place of [PubDir]. In either case, "Remove Extracted Files when Publication Terminates" must be checked.