detecting_20a_20second_20instance_20of_20a_20program
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
detecting_20a_20second_20instance_20of_20a_20program [2018/03/31 13:19] – external edit 127.0.0.1 | detecting_20a_20second_20instance_20of_20a_20program [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Detecting a second instance of a program===== | =====Detecting a second instance of a program===== | ||
- | //by Richard Russell, July 2006//\\ \\ There may be situations when you need to ensure that only one copy of a program can be run at a time; an attempt to run a second copy should fail (with or without an error message being displayed). There are several ways in which this can be achieved, but the one described here is relatively simple and free from unwanted side effects; it uses the Windows API.\\ \\ At the very start of your program add the following code:\\ \\ | + | //by Richard Russell, July 2006//\\ \\ There may be situations when you need to ensure that only one copy of a program can be run at a time; an attempt to run a second copy should fail (with or without an error message being displayed). There are several ways in which this can be achieved, but the one described here is relatively simple and free from unwanted side effects; it uses the Windows API.\\ \\ At the very start of your program add the following code: |
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
Line 8: | Line 10: | ||
QUIT | QUIT | ||
ENDIF | ENDIF | ||
- | You should replace the string **UniqueLockName** with a name which is extremely unlikely to be chosen by another program. It can consist of up to 260 characters so you can incorporate your program' | + | </ |
+ | |||
+ | You should replace the string **UniqueLockName** with a name which is extremely unlikely to be chosen by another program. It can consist of up to 260 characters so you can incorporate your program' | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
- | Ideally you should execute this code even if the program terminates abnormally, but in the event of a crash Windows should automatically delete the //mutex// for you.\\ \\ With the above code an attempt to run a second copy of a program will fail with no error message. If you want to alert the user to the problem you can display a message box by amending the code at the beginning of the program as follows:\\ \\ | + | </ |
+ | |||
+ | Ideally you should execute this code even if the program terminates abnormally, but in the event of a crash Windows should automatically delete the //mutex// for you.\\ \\ With the above code an attempt to run a second copy of a program will fail with no error message. If you want to alert the user to the problem you can display a message box by amending the code at the beginning of the program as follows: | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
Line 19: | Line 29: | ||
QUIT | QUIT | ||
ENDIF | ENDIF | ||
+ | </ |
detecting_20a_20second_20instance_20of_20a_20program.1522502354.txt.gz · Last modified: 2024/01/05 00:18 (external edit)