#include once "window9.bi"

#ifdef UNICODE
	Sub SetRunOnlyExe() export
		Dim As USTRING sName = wspace(512)
		GetModuleFileName(0,cast(any ptr , *sName),512)
		sName = GetFilePart(sName)
		sName=ReplaceString(sName,".exe","")
		if CreateSemaphore(0, 0, 1,cast(any ptr , *sName) )<>0 and GetLastError() = ERROR_ALREADY_EXISTS then
			End 1
		end If
	End sub	
#else	
	Sub SetRunOnlyExe() export
		Dim As USTRING*512 sName
		GetModuleFileName(0,Cast(LPSTR,@sName),512)
		sName = GetFilePart(sName)
		sName=ReplaceString(sName,".exe","")
		if CreateSemaphore(0, 0, 1,sName )<>0 and GetLastError() = ERROR_ALREADY_EXISTS then
			End 1
		end If
	End sub	
#EndIf
