Skip navigation

JSI Tip 0760. How do I prevent more than one instance of an application from running?

There is no standard way to do this. I use a batch file. Here is a sample AppName.bat:

@echo off
if exist %temp%\ exit
@echo date /t > %temp%\
@echo time /t >> %temp%\
start /wait /D<StartInFolder> \[Other Switches and parameters\] <StartInFolder>\appname.exe
del /q %temp%\

Alter the existing shortcut and replace the Target with <Path>\AppName.bat. and set Run: to minimized

Why does this work?

When you click the shortcut the first time, %temp%\ does not exist.
It is them created by the @echo date/t command.
The application is started by the Start command and the batch waits (/wait) till the application is terminated.
When the application is ended, the del /q %temp%\ removes the application is running file.
If you click on the shortcut while the application is running, the if exist %temp%\ immediatley terminates this new execution.

See tip 766.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.