TerminateProcess has a lot's of disadvantages as everyone knows, so I didn't want to use it. After some research I discovered that ExiProcess do deatach all DLLs:

If a process is terminated by ExitProcess, the system calls the entry-point function of each attached DLL with a value indicating that the process is detaching from the DLL. DLLs are not notified when a process is terminated by TerminateProcess. For more information about DLLs, see Dynamic-Link Libraries.

So I came up with this function:

KillProcess proc pid:DWORD
    LOCAL hProcess:HANDLE, bSuccess:DWORD
    mov bSuccess, FALSE
    invoke OpenProcess,PROCESS_ALL_ACCESS,FALSE,pid
    .if eax != NULL
        mov hProcess, eax
        fn GetModuleHandle, "Kernel32"
        fn GetProcAddress, eax, "ExitProcess"
        invoke CreateRemoteThread, hProcess, NULL, 0, eax, NULL, 0, NULL
        .if eax != NULL
            invoke CloseHandle, eax
            mov bSuccess, TRUE
        invoke CloseHandle, hProcess
    mov eax, bSuccess
KillProcess endp

And it works finely, but I wonder if it's safe or just as safe as TerminateProcess?
Posted on 2005-10-26 16:19:56 by Lenin
thats a hot idea
Posted on 2005-10-31 11:59:13 by Qages
I've been using a similar method myself - the only thing I can think of that could be problematic would be NT with a non-admin account... there might be situations where you have privileges to use TerminateProcess but where you're not allowed to inject threads. Pretty much a non-issue to me, though :)
Posted on 2005-10-31 12:17:12 by f0dder
Glad to hear that :)

Just so I won't have to make a new thread about it: I'm making a task manager, but I'm having problems with updating the list view with the new processes... How does the real task manager updates itself without loosing the current selection and positions of the itens? Updation (sp?) to me would be delete all itens and insert the new ones, but that obviously not what the real task manager uses...
Posted on 2005-11-01 15:50:37 by Lenin
Try using a listview in virtual mode?
Posted on 2005-11-01 15:57:08 by f0dder
Could you give me an example? MSDN gave me lot's of compability issues but no examples...
Posted on 2005-11-01 16:47:55 by Lenin