Hi Carlos,
We used to use Mutex, but I think we changed as it did not detect when the application was running under another user on a Terminal Server. We switched to use the WbemScripting Windows object and it is a very small amount of code. It will only work for runtime app, you can still run another copy of the app in PB on the same PC, which is handy for testing.
Try the following:
//Code to check whether Application is already running
OleObject locator, service, app
String ls_query = 'select name , description from Win32_Process where name = "APPNAME.exe" '
int num, ret
locator = CREATE OleObject
ret = locator.ConnectToNewObject("WbemScripting.SWbemLocator");
service = locator.ConnectServer();
app= service.ExecQuery(ls_query);
num = app.count()
IF num > 1 THEN
MessageBox ("Process","Application is already running on this computer!")
halt
ELSE
//Code to execute if app not already running!
END IF
//End of Code
Hope That Helps
Michael
Note that starting in W10, you must use the Unicode version of this API call. When I migrated to PB 12.6 under W10 for the first time, I had to change my framework to use the Unicode version before this feature would work properly / consistently.
FUNCTION uLong CreateMutex ( uLong lpMutexAttributes, Boolean bInitialOwner, ref string lpName ) LIBRARY "KERNEL32.dll" ALIAS FOR CreateMutexW
HTH
Regards ... Chris