Assembly language > Assembly discussions

Listing processes

(1/1)

Vortex:
Here is a quick example to list running processes :


--- Code: ---include     Process.inc

.data

text1       db 'Process name: %s',9,9,'Process ID: %d',9,9,'Parent process: %d',13,10,0

.code

start:

    call    main
    invoke  ExitProcess,0

main PROC USES esi

LOCAL pe32:PROCESSENTRY32
LOCAL hProcessSnap:DWORD

    lea     esi,pe32
    invoke  CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
    mov     hProcessSnap,eax

    mov     pe32.dwSize,SIZEOF PROCESSENTRY32
    invoke  Process32First,eax,esi

@@:
    invoke  printf,ADDR text1,ADDR PROCESSENTRY32.szExeFile[esi],\
            PROCESSENTRY32.th32ProcessID[esi],\
            PROCESSENTRY32.th32ParentProcessID[esi]

    invoke  Process32Next,hProcessSnap,esi
    test    eax,eax
    jnz     @b
   
    invoke  CloseHandle,hProcessSnap
    ret

main ENDP

END start

--- End code ---

Navigation

[0] Message Index

Go to full version