Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I know if process is running
Message
 
To
08/03/2002 17:56:25
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00630457
Message ID:
00631410
Views:
22
This message has been marked as the solution to the initial question of the thread.
hi,

If you to desire to know if "calc.exe" this being executed, uses the
program below:
#DEFINE TH32CS_SNAPPROCESS  2 
#DEFINE TH32CS_SNAPTHREAD   4 
#DEFINE TH32CS_SNAPMODULE   8 
#DEFINE MAX_PATH          260 
#DEFINE PE32_SIZE  296 

DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject 

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   

LOCAL hSnapshot, lcBuffer 

hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0) 
lcBuffer = num2dword(PE32_SIZE) + Repli(Chr(0), PE32_SIZE-4) 

IF Process32First (hSnapshot, @lcBuffer) = 1 
    * storing process properties to the cursor 
    if VerProcessExec (lcBuffer,"calc.exe")
    	=messagebox("Calculator is running")
    endif

    DO WHILE .T. 
        IF Process32Next (hSnapshot, @lcBuffer) = 1 
	        if VerProcessExec (lcBuffer,"calc.exe")
        	=messagebox("Calculator is running")
		    endif
        ELSE 
            EXIT 
        ENDIF 
    ENDDO 
ELSE 
* 87 - ERROR_INVALID_PARAMETER 
ENDIF 

= CloseHandle (hSnapshot) 
RETURN  && main 

function VerProcessExec(lcBuffer,lcExec)
    m.execname = SUBSTR(lcBuffer, 37) 
    m.execname = SUBSTR(m.execname, 1, AT(Chr(0),m.execname)-1) 
RETURN upper(m.lcExec)$m.execname

FUNCTION  num2dword (lnValue) 
#DEFINE m0       256 
#DEFINE m1     65536 
#DEFINE m2  16777216 
    LOCAL b0, b1, b2, b3 
    b3 = Int(lnValue/m2) 
    b2 = Int((lnValue - b3*m2)/m1) 
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0) 
    b0 = Mod(lnValue, m0) 
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3) 
This routine and an modification of http://www.news2news.com/vfp/?example=164&function=250

[]s
Cordialmente,

Fabiano Costa
Previous
Reply
Map
View

Click here to load this message in the networking platform