Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "PSAPI.INC"
Function PBMain
Dim aProcesses(0 To 1023) As Dword
Local cbNeeded, cProcesses,i As Dword, temp$
If IsFalse EnumProcesses(aProcesses(LBound(aProcesses)), _
(UBound(aProcesses) - LBound(aProcesses) + 1) * 4, cbNeeded) Then Exit Function
cProcesses = cbNeeded \ 4
For i = 0 To cProcesses - 1
temp$ = temp$ + $CrLf + GetProcessName(aProcesses(i))
Next
? temp$
End Function
Function GetProcessName (ByVal processID As Dword) As String
Local szProcessName As AsciiZ * %Max_Path, hProcess, hMod, cbNeeded As Dword, temp$
szProcessName = "unknown"
'// Get a handle to the process.
hProcess = OpenProcess(%PROCESS_QUERY_INFORMATION Or %PROCESS_VM_READ, %FALSE, processID)
'// Get the process name.
If IsFalse hProcess Then Exit Function
If IsFalse EnumProcessModules(hProcess, hMod, SizeOf(hMod), cbNeeded) Then Exit Function
GetModuleBaseName hProcess, hMod, szProcessName, SizeOf(szProcessName)
'// Print the process name and identifier.
temp$ = szProcessName
Function = temp$
CloseHandle hProcess
End Function
'gbs_01463
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm