;Autor: PureLust EnableExplicit Global g_hMutexAppRunning Define EventID Procedure AppInstanceExists() Protected bAppRunning = #False g_hMutexAppRunning = CreateMutex_( #Null, #Null, "Global\MyApplication1") If (g_hMutexAppRunning <> #Null) And (GetLastError_() = #ERROR_ALREADY_EXISTS) CloseHandle_( g_hMutexAppRunning ) g_hMutexAppRunning = #Null EndIf If g_hMutexAppRunning ProcedureReturn #False Else ProcedureReturn #True EndIf EndProcedure If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) If AppInstanceExists() MessageRequester("", "Die Anwendung läuft bereits."+Chr(13)+"Die zweite Instanz wird beendet.",#MB_ICONERROR) CloseHandle_(g_hMutexAppRunning) End Else MessageRequester("", "Die Anwendung läuft noch nicht."+Chr(13)+"Das ist die erste Instanz.",#MB_ICONINFORMATION) EndIf Repeat EventID=WaitWindowEvent() If EventID = #PB_Event_CloseWindow CloseHandle_(g_hMutexAppRunning) EndIf Until EventID = #PB_Event_CloseWindow EndIf