Running from studio single process in debug mode

Started by erezpaz, August 20, 2019, 02:30:50 AM

Previous topic - Next topic

erezpaz

Hi,

I am using an example from here how to run only one process instate of my program.
DupThread = 0
kernel32=strcat(dirwindows(1),"kernel32.dll")
ERROR_ALREADY_EXISTS=183
mutexname="*mywinbatchappnamev1.x*"
hmutex=dllcall(kernel32,long:"CreateMutexA",lpnull,long:0,lpstr:mutexname)
if DllLastError()==ERROR_ALREADY_EXISTS ;mutex exist an hinstance is running
display(5,NameVer,"Only 1 instance of %tool% is allowed.")
exit
end if
It works fine when i run the exe directly. If i run it from the studio in regular mode or debug mode i get the message and the program exit.
Can you help me understand how to prevent that?

Thanks

kdmoyers

Just a data point: it's working fine for me on my Win7 and Win10 machines.
(I had to define NameVer)
Thanks for the cool example!
$0.02
-Kirby
The mind is everything; What you think, you become.

td

When you call your function from the WinBatch Studio debugger,  the mutex remains in existence even after the debugging session ends because the WinBatch Studio process is still running.

Also, is there some reason why you are not using the AppExist function instead of fiddling with a DllCall?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

If there is a good reason to be using a DllCall instead of AppExist, you can always simply close the mutex handle using the Win32 CloseHandle function just before the script terminates.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade