General information
Category:
Windows API functions
Environment versions
Network:
Windows 2000 Server
The following code is what we use to achieve this:
*************************************************************************************
*$METHOD$ spIsProcessRunning()
*
*$PURPOSE$
* Searches through the task list and sees if the passed process is
* currently executing on the local machine.
*$PURPOSE$
*************************************************************************************
FUNCTION spIsProcessRunning
LPARAMETERS vcProcessName, rcErrors
#DEFINE PROCESS_QUERY_INFORMATION 0x400
#DEFINE PROCESS_VM_READ 0x10
#DEFINE PROCESS_ALL_ACCESS 0x1f0fff
#DEFINE PROCESS_MASK BITOR(PROCESS_QUERY_INFORMATION,PROCESS_VM_READ)
declare integer GetLastError in win32api
declare integer EnumProcesses in psapi string@, integer, integer@
declare integer EnumProcessModules in psapi integer, string@, integer, integer@
declare integer GetModuleFileNameEx in psapi integer, integer, string@, integer
declare integer OpenProcess in kernel32 integer, integer, integer
declare integer CloseHandle in kernel32 integer
declare string GetCommandLine in kernel32 integer
LOCAL lcPIDArray, lcModArray, lnSize, lnNeeded, lcArrstr, lnMod, llProcess, ;
lnNeeded, lnCount, lnHProc, lnModLen, lnCount2, llReturn, lcModName
lcPIDArray = REPLICATE(CHR(0), 4096)
lnSize = 200
lnNeeded = 0
lnModLen = 0
IF EnumProcesses(@lcPIDarray, lnSize, @lnNeeded) <> 0
lcPIDarray = LEFT(lcPIDarray,lnNeeded)
FOR lnCount = 1 TO lnNeeded STEP 4
lnPID = spStr2Long(SUBSTR(lcPIDArray, lnCount, 4))
IF lnPID <> 0
lnHProc = OpenProcess(PROCESS_MASK, 0, lnPID)
IF lnHProc <> 0
lcModArray = REPLICATE(CHR(0),8192)
IF EnumProcessModules(lnHProc, @lcModArray, lnSize, @lnModLen) <> 0
llProcess = .F.
FOR lnCount2 = 1 to 1 step 4
lnMod = spStr2Long(SUBSTR(lcModArray,lnCount2, 4))
IF lnMod <> 0
lcModName = REPLICATE(CHR(0),128)
GetModuleFileNameEx(lnHProc, lnMod, @lcModName, 128)
IF !llprocess AND (lnCount2 = 1 AND !("VFP" $ UPPER(lcModName)))
llprocess = .T.
ENDIF
IF !llprocess
EXIT
ENDIF
IF UPPER(JUSTFNAME(LEFT(lcModName,AT(CHR(0),lcModName)-1))) == UPPER(vcProcessName)
llReturn = .t.
EXIT
ENDIF
ENDIF
NEXT
ENDIF
CloseHandle(lnHProc)
ENDIF
ENDIF
IF llReturn
*-- We have a match so don't bother going any further
EXIT
ENDIF
NEXT
ELSE
*-- We have an error
rcError = transform(GetLastError())
ENDIF
RETURN llReturn
ENDFUNC
FUNCTION spStr2Long
LPARAMETERS vcLongStr
LOCAL lnCount, lnReturn
lnReturn = 0
FOR lnCount = 0 TO 24 STEP 8
lnReturn = lnReturn + (ASC(vcLongStr) * (2^lnCount))
vcLongStr = RIGHT(vcLongStr, LEN(vcLongStr) - 1)
NEXT
RETURN lnReturn
ENDFUNC
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only