Jump to content
Sign in to follow this  

Howto List loaded Dlls

Recommended Posts



i want to list all Processes with Name and Pid, which use one Dll. The Code only searches inside the processes of the user .. not in all processes like System, network , local etc.. It should search everywhere not only in process of the user. Does anybody know what is wrong here?

After that i want to unload the dll from all process (but this is the next step - perhaps someone could also help to code this ?? )

I´m a newbie, so please excuse my errors... :


_ListDlls ("kernel32")

Func _ListDlls ($DllName)

Local $Proclist = ProcessList()

Local $ProcMod, $Result,$test

Local $i,$t

For $i = 1 to UBound($Proclist)-1

If $Proclist[$i][1] > 0 Then

$ProcMod = _ProcessListModules($Proclist[$i][0])

For $t = 1 to UBound($ProcMod)-1

If StringInStr(StringLower($ProcMod[$t][1]),StringLower($DllName)) <> 0 Then

$Result = $Result & "Process: " & $Proclist[$i][0] & " " & "PID: " & $Proclist[$i][1] & @CRLF & "Dll: " & $ProcMod[$t][1] & @CRLF & @CRLF





msgbox (0,"Testfinish",$Result)


Func _ProcessListModules($dwPID)

If IsInt($dwPID) = 0 Then $dwPID = ProcessExists($dwPID)

Local Const $TH32CS_SNAPALL = BitOR(0x01, 0x08, 0x02, 0x04)

Local $aDLLCall, $tagMODULEENTRY32, $hModuleSnap

$aDLLCall = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPALL, "dword", $dwPID)

If @error Or $aDLLCall[0] = 0xFFFFFFFF Then Return SetError(1, 0, 0)

$hModuleSnap = $aDLLCall[0]

$tagMODULEENTRY32 = DllStructCreate("dword;dword;dword;dword;dword;byte;dword;uint;char[257];char[256]")

DllStructSetData($tagMODULEENTRY32, 1, DllStructGetSize($tagMODULEENTRY32))

$aDLLCall = DllCall("Kernel32.dll", "int", "Module32First", "ptr", $hModuleSnap, "long", DllStructGetPtr($tagMODULEENTRY32))

If @error Or Not $aDLLCall[0] Then Return SetError(2, DllCall("Kernel32.dll", "int", "CloseHandle", "ptr", $hModuleSnap), 0)

Local $avArray[2][2], $iAdd = 1

While 1

$avArray[$iAdd][0] = DllStructGetData($tagMODULEENTRY32, 9) ; File Name

$avArray[$iAdd][1] = DllStructGetData($tagMODULEENTRY32, 10) ; File Path

$aDLLCall = DllCall("kernel32", "int", "Module32Next", "ptr", $hModuleSnap, "long", DllStructGetPtr($tagMODULEENTRY32))

If @error Then Return SetError(3, DllCall("Kernel32.dll", "int", "CloseHandle", "ptr", $hModuleSnap), 0)

If Not $aDLLCall[0] Then ExitLoop

$iAdd += 1

ReDim $avArray[$iAdd + 1][2]


DllCall("Kernel32.dll", "int", "CloseHandle", "ptr", $hModuleSnap)

$avArray[0][0] = $iAdd

Return $avArray


Edited by badzox

Share this post

Link to post
Share on other sites

Tasklist doesn´t list all Dlls ! From Services per Expamle. Ic checked It with Sysinternals ListDlls.

I would like to do it without tasklist only per Script. Hopefully only with Kernel Dlls.... Can someone look over the code above ?

Edited by badzox

Share this post

Link to post
Share on other sites

Anyone out there who wanna help out ?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this