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%\appname.run exit
@echo date /t > %temp%\appname.run
@echo time /t >> %temp%\appname.run
start /wait /D<StartInFolder> \[Other Switches and parameters\] <StartInFolder>\appname.exe
del /q %temp%\appname.run
exit

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%\appname.run 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%\appname.run removes the application is running file.
If you click on the shortcut while the application is running, the if exist %temp%\appname.run immediatley terminates this new execution.

See tip 766.

Hide comments

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.
Publish