Jerry:
I use this.
lnRet = process_running("DEVSCOUT.EXE") &&  always return the program is 
running -
if lnRet > 0 then
  do form running.scx
  cancel
endif

procedure process_running
lparameter lcProcess_to_check
lnProcID = procID(lcProcess_to_check)
return lnProcID
***************************************************************************************************
FUNCTION ProcID(tcProcessName)
 IF pcount() = 0
  *** Nothing to do
  RETURN 0
 ENDIF
 IF TYPE("tcProcessName") # "C"
  RETURN 0
 ENDIF
 LOCAL lcProcessName, lnBufSize, lcProcInfo, lnResult, lnProcID, 
th32DefaultHeapID
 LOCAL cntUsage, th32ProcessID, th32ModuleID, cntThreads, th32ParentProcessID, 
pcPriClassBase, dwFlags, szExeFile
 lcProcessName = ALLTRIM(tcProcessName)
 IF EMPTY(lcProcessName)
  RETURN 0
 ENDIF
 *** Declare DLLs needed for the case
 DECLARE INTEGER CreateToolhelp32Snapshot IN Kernel32 INTEGER dwFlags, INTEGER 
th32ProcessID
 DECLARE INTEGER Process32First IN kernel32 INTEGER hSnapshot, STRING @lpPE
 DECLARE INTEGER Process32Next IN kernel32 INTEGER hSnapshot, STRING @ lpPE
 DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
 #DEFINE TH32CS_SNAPPROCESS   0x00000002
 *** Structure used in Process32First() and Process32Next() functions
 *!*   typedef struct tagPROCESSENTRY32 {
 *!*     DWORD dwSize;     32
 *!*     DWORD cntUsage;     32
 *!*     DWORD th32ProcessID;   32
 *!*     ULONG_PTR th32DefaultHeapID; 32
 *!*     DWORD th32ModuleID;    32
 *!*     DWORD cntThreads;    32
 *!*     DWORD th32ParentProcessID;  32
 *!*     LONG pcPriClassBase;   32
 *!*     DWORD dwFlags;     32
 *!*     TCHAR szExeFile[MAX_PATH];  260+1
 *!*   } PROCESSENTRY32, *PPROCESSENTRY32;
 *** Therefore, 288+ 261 = 549 - make it 550
 *** Obtain a handle to the thread's snapshot
 hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
 lnBufSize = 550
 lcProcInfo = num2dword(lnBufSize) + REPLICATE(CHR(0), lnBufSize -32)
 *** Get the first process
 lnResult = Process32First(hSnapShot, @lcProcInfo)
 lnProcID = 0
 *** Cycle through the rest of the processes until the one in ? found (or 
not...)
 DO WHILE lnResult # 0
  *** We will use only the th32ProcessID and szExeFile, but will extract all 
just in case...
  th32ProcessID = buf2dword(SUBSTR(lcProcInfo, 9, 4))
  szExeFile = STRTRAN(SUBSTR(lcProcInfo,37), CHR(0), "")
  *** Check if we have found the process in ?
  IF ATC(lcProcessName, szExeFile) # 0
   lnProcID = th32ProcessID
   EXIT  && DO WHILE...ENDDO cycle
  ENDIF
  *** Reinit lcProcInfo just "FileName" part so in XP file name does not get 
cluttered
  ***   and in Win9x & ME could do the "Process32Next" corectly
  lcProcInfo= SUBSTR(lcProcInfo,1,36) +REPLICATE(CHR(0), lnBufSize - 36)
  lnResult = Process32Next(hSnapShot, @lcProcInfo)
 ENDDO
 = CloseHandle(hSnapShot)
 CLEAR DLLS CreateToolhelp32Snapshot, Process32First, Process32Next, CloseHandle
 RETURN lnProcID
ENDFUNC  &&ProcID
******************************************************************************************************************************
FUNCTION Num2DWORD(tnValue)
 #DEFINE m0       256
 #DEFINE m1     65536
 #DEFINE m2  16777216
 LOCAL b0, b1, b2, b3
 b3 = INT(tnValue / m2)
 b2 = INT((tnValue - b3 * m2) / m1)
 b1 = INT((tnValue - b3 * m2 - b2 * m1) / m0)
 b0 = MOD(tnValue, m0)
 RETURN CHR(b0) + CHR(b1) + CHR(b2) + CHR(b3)
ENDFUNC  &&Num2DWORD
******************************************************************************************************************************
FUNCTION Buf2DWORD(tcBuffer)
 IF TYPE('tcBuffer') # "C"
  RETURN 0
 ENDIF
 tcBuffer = LEFT(ALLTRIM(tcBuffer), 4)
 LOCAL I, lnRet
 lnRet = ASC(SUBSTR(tcBuffer, 1, 1))
 FOR I = 1 TO 3
  lnRet = lnRet + ASC(SUBSTR(tcBuffer, I + 1, 1)) * 256^I
 NEXT I
 RETURN INT(lnRet)
ENDFUNC  &&Buf2DWORD

There is probably a better way but this one works ok.
Jack Skelley


Jack Skelley
Senior Director, Programming/Computer Operations
New Jersey Devils
(973)757-6164
[email protected] ________________________________________
From: ProfoxTech [[email protected]] on behalf of jerry foote 
[[email protected]]
Sent: Monday, February 18, 2013 9:14 AM
To: [email protected]
Subject: Program already running

I have a program written in vfp8 running on xp. I HAVE to stop a second
instance of the program from running.

Any suggestions.

Jerry



--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/7d9e7f72b813014c8fd022cf04f820ed585e2...@ex08.drdad.thenewarkarena.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to