Click to See Complete Forum and Search --> : Can't get code to work


inhumanoid
October 20th, 1999, 05:23 AM
I am trying to get the following code to work, but I cant seem to cope.
Could someone try to create a small project using this code (also tell me wich controls to put on the form e.d.).
thanx



Windows API/Global Declarations:
Note:This code is formatted to be pasted directly into VB, Java, C or C++.
Pasting it into other editors may or may not work.



'***************************************************************
'Windows API/Global Declarations for :List All Active Processes (
' Class)
'***************************************************************
option Explicit' Name: List All Active Processes
' Author:Chong Long Choo
' Email: chonglongchoo@hotmail.com
' date: 09 September 1999
'<--------------------------Disclaimer------------------------
' ------->
'
'This sample is free. You can use the sample in any form. Use thi
' s
'sample at your own risk! I have no warranty for this sample.
'
'<--------------------------Disclaimer------------------------
' ------->
'----------------------------------------------------------------
' -----------------
'How to use
'----------------------------------------------------------------
' -----------------
'Dim i as Integer
'Dim objItem as ListItem
'Dim NumOfProcess as Long
'Dim objActiveProcess as SQLSysInfo.clsActiveProcess
'set objActiveProcess = new SQLSysInfo.clsActiveProcess
'NumOfProcess = objActiveProcess.GetActiveProcess
'for i = 1 to NumOfProcess
'set objItem = ListView2.ListItems.Add(, , objActiveProcess.szExe
' File(i))
'With objItem
'.SubItems(1) = objActiveProcess.th32ProcessID(i)
'.SubItems(2) = objActiveProcess.th32DefaultHeapID(i)
'.SubItems(3) = objActiveProcess.thModuleID(i)
'.SubItems(4) = objActiveProcess.cntThreads(i)
'.SubItems(5) = objActiveProcess.th32ParentProcessID(i)
'End With
'next
'set objActiveProcess = nothing
private Const TH32CS_SNAPPROCESS as Long = 2&private Const MAX_PATH as Integer = 260

private Type PROCESSENTRY32 dwSize as Long cntUsage as Long th32ProcessID as Long th32DefaultHeapID as Long th32ModuleID as Long cntThreads as Long th32ParentProcessID as Long pcPriClassBase as Long dwFlags as Long szExeFile as string * MAX_PATH End Type

private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (byval lFlags as Long, byval lProcessID as Long) as Long

private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (byval hSnapShot as Long, uProcess as PROCESSENTRY32) as Long

private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (byval hSnapShot as Long, uProcess as PROCESSENTRY32) as Long

private Declare Sub CloseHandle Lib "kernel32" (byval hPass as Long) Dim ListOfActiveProcess() as PROCESSENTRY32



Source Code:
Note:This code is formatted to be pasted directly into VB, Java, C or C++.
Pasting it into other editors may or may not work.



'***************************************************************
' Name: List All Active Processes (Class)
' Description:List All Active Processes (Class)
' By: Chong Long Choo
'
'
' Inputs:None
'
' Returns:None
'
'Assumes:None
'
'Side Effects:None
'
'Code provided by Planet Source Code(tm) (http://www.Planet-Sourc
' e-Code.com) 'as is', without warranties as to performance, fitnes
' s, merchantability,and any other warranty (whether expressed or i
' mplied).
'Distribution of this source code is copyrighted by Planet Source
' Code who has exclusive rights to distribute it.
'It is freely redistributable for personal use in source code for
' m, or for personal or business use in a non-source code binary ex
' ecutable.
'All other redistributions are prohibited without express written
' consent from Exhedra Solutions, Inc.
'***************************************************************


public Function szExeFile(byval Index as Long) as string

szExeFile = ListOfActiveProcess(Index).szExeFileEnd Function



public Function dwFlags(byval Index as Long) as Long

dwFlags = ListOfActiveProcess(Index).dwFlagsEnd Function



public Function pcPriClassBase(byval Index as Long) as Long

pcPriClassBase = ListOfActiveProcess(Index).pcPriClassBaseEnd Function



public Function th32ParentProcessID(byval Index as Long) as Long

th32ParentProcessID = ListOfActiveProcess(Index).th32ParentProcessIDEnd Function



public Function cntThreads(byval Index as Long) as Long

cntThreads = ListOfActiveProcess(Index).cntThreadsEnd Function



public Function thModuleID(byval Index as Long) as Long

thModuleID = ListOfActiveProcess(Index).th32ModuleIDEnd Function



public Function th32DefaultHeapID(byval Index as Long) as Long

th32DefaultHeapID = ListOfActiveProcess(Index).th32DefaultHeapIDEnd Function



public Function th32ProcessID(byval Index as Long) as Long

th32ProcessID = ListOfActiveProcess(Index).th32ProcessIDEnd Function



public Function cntUsage(byval Index as Long) as Long

cntUsage = ListOfActiveProcess(Index).cntUsageEnd Function



public Function dwSize(byval Index as Long) as Long

dwSize = ListOfActiveProcess(Index).dwSizeEnd Function



public Function GetActiveProcess() as Long

Dim hToolhelpSnapshot as Long Dim tProcess as PROCESSENTRY32 Dim r as Long, i as Integer hToolhelpSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)

If hToolhelpSnapshot = 0 then GetActiveProcess = 0 Exit Function End If



With tProcess .dwSize = len(tProcess) r = ProcessFirst(hToolhelpSnapshot, tProcess) ReDim Preserve ListOfActiveProcess(20)

Do While r i = i + 1 If i Mod 20 = 0 then ReDim Preserve ListOfActiveProcess(i + 20) ListOfActiveProcess(i) = tProcess r = ProcessNext(hToolhelpSnapshot, tProcess) Loop

End With

GetActiveProcess = i Call CloseHandle(hToolhelpSnapshot)End Function

Lothar Haensler
October 20th, 1999, 06:14 AM
keep in mind that CreateToolhelp... functions are not available in NT prior to version 5.0!