RosettaCodeData/Task/Determine-if-only-one-instance-is-running/Liberty-BASIC/determine-if-only-one-instance-is-running.basic
2023-07-01 13:44:08 -04:00

16 lines
792 B
Text

'Create a Mutex to prevent more than one instance from being open at a single time.
CallDLL #kernel32, "CreateMutexA", 0 as Long, 1 as Long, "Global\My Program" as ptr, mutex as ulong
CallDLL #kernel32, "GetLastError", LastError as Long
if LastError = 183 then 'Error returned when a Mutex already exists
'Close the handle if the mutex already exists
calldll #kernel32, "CloseHandle", mutex as ulong, ret as ulong
notice "An instance of My Program is currently running!"
end
end if
'Release the Mutex/ Close the handle prior to ending the program
'Comment out these lines to allow the program to remain active to test for the mutex's presence
calldll #kernel32, "ReleaseMutex", mutex as ulong, ret as ulong
calldll #kernel32, "CloseHandle", mutex as ulong, ret as ulong
end