It seems the global environment variables are copied into their own "local" instance each time you run the program. For example, just run the program, then run CMD, and type "set i". There is no "im_running", because it's local to your program instance.
Anyway, there is a much better way to do what you want. Use a Mutex. Here is an example:
Anyway, there is a much better way to do what you want. Use a Mutex. Here is an example:
; .lib "kernel32.dll" ; CreateMutex%(lpMutexAttributes%,bInitialOwner%,lpName$):"CreateMutexA" ; GetLastError%():"GetLastError" Const ERROR_ALREADY_EXISTS=183 CreateMutex(0,1,"My Program Instance") ; Mutex accessible to any program If GetLastError() = ERROR_ALREADY_EXISTS Then Notify "My program is already running" ; Shutdown Else Notify "This is the only instance of My Program" ; OK EndIf