Archive: Killing a Process


Killing a Process
  I have a process on my machine which I need to kill off, I've tried:

System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_CLOSE},0,0)'
SendMessage $0 "000E" 0 0 ; WM_GETTEXTLENGTH ????
SendMessage $0 "0002" 0 0 ; WM_DESTROY
SendMessage $0 "0082" 0 0 ; WM_NCDESTROY
SendMessage $0 "0111" "E141" 0 ; WM_AppExit
SendMessage $0 "16" 0 0 ; WM_CLOSE

But it does not working.

Speaking to the developer he says you need to kill the process, like if you use Task manager and End Task.

He has suggested using:

getwindowthreadprocessid

Anyone know how I can do this?


I think the calls you need to make are (in order)
1) FindWindow
2) GetWindowThreadProcessID
3) OpenProcess with PROCESS_TERMINATE
4) TerminateProcess, try a big exit code

I can do the FindWindow okay.

But how do I implement them into NSIS?


Not Tested:

!define PROCESS_TERMINATE 0x0001


FindWindow$0 "WindowClass"
>System::Call "User32::GetWindowThreadProcessId(i,*i)i(r0,.r0)"
>System::Call "Kernel32::OpenProcess(i,i,i)i (${PROCESS_TERMINATE}, 1, r0) .r0"
>System::Call "Kernel32::GetExitCodeProcess(i,*i)i (r0,.r1)"
>System::Call "Kernel32::TerminateProcess(i,i)i (r0,r1)"

Hi :)

There is a nice plugin that just does everything for you : KillProcDll

It can be found here :
http://nsis.sourceforge.net/archive/download.php

evilO/Olive


Many thanks, tested and working on 98, ME, 2000 and XP.

But the Kill Process fails on NT Workstation :-(


Doh !! I didn't know that :eek: !
Well, sorry :( ...

evilO/Olive


You can also try nopey. Which is available in the archive here at the bottom.

http://nsis.sourceforge.net/archive/download.php

Killing processes is one of it's features.


I'm impressed with my code posted above, I didn't test at that time (I was going to school) and it worked when I tested it now. It's rare to work when I don't test.


deguix

GetExitCodeProcess() in your script will always return STILL_RUNNING,
and next TerminateProcess() sets STILL_RUNNING as process exit code. Another words, after process was terminated and while process handle is not closed (CloseHandle()), any following GetExitCodeProcess() call will return STILL_RUNNING – little confusing situation :)