This is slightly different to how _Singleton() (Misc.au3) works by Valik, because firstly this function uses the hidden window of an AutoIt executable and secondly it returns the PID of the main executable, not the handle to the object used for synchronization. It should also be noted that $iFlag parameter 2 doesn't exist in this function and if no program exists already _SingletonPID() returns 0. Any suggestions are welcome. Thanks.
Function:
#include <StringConstants.au3>