General information
Category:
Windows API functions
Environment versions
Network:
Windows 2000 Server
Hi Mark,
Try with my example.
Regards,
---------------------------------------------------------------------------------------
*|------------------------------------------------------------------------------------------
*|--
*|-- Autor : Roberto C. Ianni
*|-- E-Mail : ianni_roberto@hotmail.com
*|--
*|------------------------------------------------------------------------------------------
Public oFrm
SET PROCEDURE TO SYS(16) ADDITIVE
oFrm = CREATEOBJECT( 'ThreadList' )
oFrm.Show()
Return
DEFINE CLASS ThreadList As Form
Name = "ThreadList"
AutoCenter = .T.
MaxButton = .F.
MinButton = .F.
ADD OBJECT lbThread AS "ListBox" WITH ;
Top = 10, ;
Left = 10, ;
Name = "lbThread", ;
ColumnCount = 2, ;
ColumnWidths = "250,100", ;
Height = ThisForm.Height - 30 , ;
Width = ThisForm.Width - 20
Sorted = .T.
PROCEDURE Init
LOCAL oProcess, lnCount
DIMENSION arrProcess[1, 2]
oProcess = CREATEOBJECT("Process")
lnCount = oProcess.GetArrayProcess( @arrProcess )
FOR I = 1 TO lnCount
This.lbThread.AddItem( ALLTRIM( arrProcess[ I, 1 ] ) )
This.lbThread.List[This.lbThread.NewIndex, 2] = ALLTRIM( STR( arrProcess[ I, 2 ] ) )
NEXT
RELEASE oProcess
ENDPROC
ENDDEFINE
DEFINE CLASS Process AS CUSTOM
Name = "Process"
#DEFINE PROCESS_TERMINATE 0x0001
#DEFINE PROCESS_CREATE_THREAD 0x0002
#DEFINE PROCESS_SET_SESSIONID 0x0004
#DEFINE PROCESS_VM_OPERATION 0x0008
#DEFINE PROCESS_VM_READ 0x0010
#DEFINE PROCESS_VM_WRITE 0x0020
#DEFINE PROCESS_DUP_HANDLE 0x0040
#DEFINE PROCESS_CREATE_PROCESS 0x0080
#DEFINE PROCESS_SET_QUOTA 0x0100
#DEFINE PROCESS_SET_INFORMATION 0x0200
#DEFINE PROCESS_QUERY_INFORMATION 0x0400
#DEFINE PROCESS_ALL_ACCESS STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF
#DEFINE SYNCHRONIZE 0x00100000L
PROCEDURE Init
*|-- Declaraciones API.-
DECLARE INTEGER CreateToolhelp32Snapshot IN win32api INTEGER, INTEGER
DECLARE INTEGER Process32First IN WIn32APi INTEGER, STRING@
DECLARE INTEGER Process32Next IN WIn32APi INTEGER, STRING@
DECLARE LONG CloseHandle IN "kernel32" LONG hObject
ENDPROC
*|-- Retorna un array con la lista de procesos que se encuentran corriendo en la maquina.-
PROCEDURE GetArrayProcess( lpArrProcess )
EXTERNAL ARRAY lpArrProcess
*|-- Declaraciones.-
LOCAL lnHandle && Handle abierto del snapshot especificado.-
LOCAL lnCount && Cantidad de procesos.-
LOCAL lnRet && Usado para verificar si se copio o no el proceso.-
LOCAL lcString && Contiene la estructura PROCESSENTRY32 en un string.-
LOCAL lcStringEmpty && Copia de lcString.-
*|-- Estructura PROCESSENTRY32.-
*!* typedef struct tagPROCESSENTRY32 {
*!* DWORD dwSize;
*!* DWORD cntUsage;
*!* DWORD th32ProcessID;
*!* ULONG_PTR th32DefaultHeapID;
*!* DWORD th32ModuleID;
*!* DWORD cntThreads;
*!* DWORD th32ParentProcessID;
*!* LONG pcPriClassBase;
*!* DWORD dwFlags;
*!* TCHAR szExeFile[MAX_PATH];
*!* } PROCESSENTRY32;
*!* typedef PROCESSENTRY32 *PPROCESSENTRY32;
*|-- sizeof( tagPROCESSENTRY32 ) = 296
*|-- Busca los procesos que se encuentran corriendo.-
lnCount = 0
lnHandle = CreateToolhelp32Snapshot( 2, 0 )
lcStringEmpty = This.long2str(296) + REPLICATE( CHR(0), 292 )
IF lnHandle > 0
lcString = lcStringEmpty
lnRet = Process32First( lnHandle, @lcString )
*|-- Si es mayor a 1, el proceso fue copiado al buffer.-
DO WHILE lnRet > 0
lnCount = lnCount+1
DIMENSION lpArrProcess[lnCount, 2]
*|-- Toma el ProcessID
lpArrProcess[lnCount, 2] = This.StringToLong( SUBSTR( lcString, 9, 4 ) )
*|-- La posición 37 es igual a propiedad szExeFile, y de ahí se busca hasta donde se encuentra
*|-- el fin del string ( que es un CHR(0) ).-
lpArrProcess[lnCount, 1] = SUBSTR( lcString, 37, LEN( lcString ) )
lpArrProcess[lnCount, 1] = SUBSTR( lpArrProcess[lnCount,1], 1, AT( CHR(0), lpArrProcess[lnCount,1] ) - 1 )
lcString = lcStringEmpty
lnRet = Process32Next( lnHandle, @lcString )
ENDDO
CloseHandle( lnHandle )
ENDIF
RETURN lnCount
ENDPROC
********************
PROCEDURE long2str( lnLongval )
********************
PRIVATE i, retstr
retstr = ""
FOR i = 24 TO 0 STEP -8
m.retstr = CHR(INT(lnLongval/(2^i))) + m.retstr
lnLongval = MOD(lnLongval, (2^i))
NEXT
RETURN m.retstr
ENDPROC
PROTECTED PROCEDURE StringToLong( m.StrAConvertir )
LOCAL I1, m.NroARetornar
m.NroARetornar = 0
FOR I1 = 0 TO 24 STEP 8
m.NroARetornar = m.NroARetornar + (ASC(m.StrAConvertir) * (2^I1))
m.StrAConvertir = RIGHT(m.StrAConvertir, LEN(m.StrAConvertir) - 1)
NEXT
RETURN m.NroARetornar
ENDPROC
ENDDEFINE
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