viewpoint-particle

Author Topic: Running from studio single process in debug mode  (Read 62 times)

erezpaz

  • Jr. Member
  • **
  • Posts: 67
Running from studio single process in debug mode
« on: August 20, 2019, 02:30:50 am »
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

  • Sr. Member
  • ****
  • Posts: 280
Re: Running from studio single process in debug mode
« Reply #1 on: August 20, 2019, 05:17:47 am »
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

  • Tech Support
  • *****
  • Posts: 3018
    • WinBatch
Re: Running from studio single process in debug mode
« Reply #2 on: August 20, 2019, 07:45:40 am »
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

  • Tech Support
  • *****
  • Posts: 3018
    • WinBatch
Re: Running from studio single process in debug mode
« Reply #3 on: August 21, 2019, 07:07:48 am »
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