Seznam DLL a OCX, na kter²ch zßvisφ proces

Postup:
Const MAX_MODULE_NAmeInfo = 255
Const MAX_PATH = 260
Const TH32CS_SNAPMODULE = &H8

Private Type MODULEENTRY32
    dwSize As Long
    th32ModuleID As Long
    th32ProcessID As Long
    GlblcntUsage As Long
    ProccntUsage As Long
    modBaseAddr As Long
    modBaseSize As Long
    hModule As Long
    szModule As String * 256
    szExePath As String * MAX_PATH
End Type

Private Declare Function CopyMemory Lib "kernel32" Alias _
    "RtlMoveMemory" (ByVal  dest As Any, ByVal source As Any, _
    ByVal bytes As Long) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias _
    "CreateToolhelp32Snapshot" (ByVal lFlags As Long, _
    ByVal lProcessID As Long) As Long
Private Declare Function Module32First Lib "kernel32" _
    (ByVal hSnapshot As Long, lpmeInfo As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "kernel32" _
    (ByVal hSnapshot As Long, lpmeInfo As MODULEENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long

' Vracφ seznam DLLs a OCX, kterΘ pou₧φvß vybran² proces
' pokud je Φφslo procesu vynechßno, bere se aktußlnφ proces
'
' JmΘna jsou ulo₧ena v elementech od 1 v nßvratovΘm poli,
' tudφ₧ UBound(result) dßvß poΦet modul∙
' Obecn∞ je prvnφ element jmΘno EXE souboru.

' POZN┴MKA: Pracuje pouze pod Win 9x a 2000 (ne NT)


Function GetProcessModules_
    (Optional ByVal processID As Long = -1) As String()

    Dim meInfo As MODULEENTRY32
    Dim success As Long
    Dim hSnapshot As Long
    ReDim res(0) As String
    Dim count As Long
    
    If processID = -1 Then processID = GetCurrentProcessId
    
    hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPMODULE, processID)
    If hSnapshot = 0 Then GoTo ExitProc
    
    meInfo.dwSize = Len(meInfo)
    
    success = Module32First(hSnapshot, meInfo)
    Do While success
        If meInfo.th32ProcessID = processID Then
            count = count + 1
            If count > UBound(res) Then
                ReDim Preserve res(count + 100) As String
            End If
            res(count) = Left$(meInfo.szExePath, InStr(meInfo.szExePath & _
                vbNullChar, vbNullChar) - 1)
        End If
        success = Module32Next(hSnapshot, meInfo)
    Loop
    
    CloseHandle hSnapshot
    
ExitProc:
    ReDim Preserve res(0 To count) As String
    
    GetProcessModules = res
End Function

Zp∞t

Autor: The Bozena