Here's a fun one.
We have code in almost all of our programs to stop multiple copies running. However on remote desktop clients we get false positives with our menu program.
Code:
Get fIsDeveloper (&gsLoginUser) to gbDeveloper
Get Module_name to gsExecutable //dont uppercase - no PID provided this program hasn't been called from a menu
Move (trim(gsExecutable-".exe")) to gsExecutable
Get CountProcess gsExecutable to giCount //should only be this 1
If (giCount > 1) Begin
If (gbDeveloper) Send showtimedmsg ("now"* String(giCount) * "copies running")
Else Begin
Send ShowTimedMsg ("Program" * gsExecutable * "Already Running") "err"
Send Exit_Application
End
End
and Countprocess is part of Enum_Processes found elsewhere in these fora
Code:
....
Function RetrieveProcessNames Global Returns String[]
tPROCESSENTRY32 ProcessInfo
Handle hProcessesSnapshot
Integer iRetval
String[] sExeFileNames
Move (WINAPI_CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0)) to hProcessesSnapshot
If (hProcessesSnapshot <> 0) Begin
Move (SizeOfType (tPROCESSENTRY32)) to ProcessInfo.dwSize
Move (WINAPI_Process32First (hProcessesSnapshot, AddressOf (ProcessInfo))) to iRetval
While (iRetval <> 0)
Move (CString(UCharArrayToString (ProcessInfo.szExeFile))) to sExeFileNames[SizeOfArray (sExeFileNames)]
Move (WINAPI_Process32Next (hProcessesSnapshot, AddressOf (ProcessInfo))) to iRetval
Loop
End
Move (WinAPI_CloseHandle(hProcessesSnapshot)) to iRetVal
Function_Return sExeFileNames
End_Function
Function CountProcess Global String sProcessName Returns Integer
Integer iInstanceCount
String[] sProcessNames
Integer iElements iElement
Move (RetrieveProcessNames ()) to sProcessNames
Move (SizeOfArray (sProcessNames) - 1) to iElements
For iElement from 0 to iElements
If (uppercase(sProcessNames[iElement]) = Uppercase(sProcessName)) Begin
Increment iInstanceCount
End
Loop
Function_Return iInstanceCount
End_Function
Works fine on normal desktops. I've used the task manager to verify that there are no copies running.
Any ideas?