-
Ending running tasks
How can I end a task that is currently running on my PC. For example when I press <Ctrl> + <Alt> + <Del> I see "winword.exe" in the Close Program dialog box. How can I end the task "winword.exe"?
Is there any function that takes the name of the task and then ends it?
-
There is a way but it's quite long and I don't have time to write it here:
every program has a HINSTANCE, this is a number that identifies the program; you find the proper HINSTANCE for the program you wanna close (that's the long part), and then use CloseHandle();
Oskilian
-
Try..
This works only if the window can be maximized/shown:
First, find the title of the window in the blue bar. Then, do this:
HWND find;
find = FindWindow(NULL, *Title of window here*);
SendMessage(find, WM_CLOSE, (LPARAM)0, (WPARAM)0);
Try that.
-
it would work, but what happens if the programmer meant to avoid this and handles the WM_CLOSE message?
Isn't there a function that finds the HINSTANCE out of a HWND?
Oskilian
-
This is your answer !
Check out on MSDN a programme called TLIST !
It shows you the running tasks visible or invisible to ctrl+alt+del and shows you how to kill them !
It`s pretty simple but about 1000 lines of C code for functions on NT and 9.x !
I created a task manager and will soon be available on my website !
I`ll let you all know !
for the source code mail me ! and i`ll send it to you by mail !
tomkat rulez !:)
-
If you use spy to watch messages you'll see that when you use end task off of the taskmanager he sends a WM_CLOSE message when he shuts down an application.
After you wait some reasonable amount of time it the task is still running you can brut force it with TerminateProcess as a last resort.
-
;################################################# #########################
; killproc
; coded by comrade
; see readme.txt
;################################################# #########################
.386
.model flat, stdcall
option casemap:none
;################################################# #########################
include C:\masm32\include\windows.inc
include C:\masm32\include\kernel32.inc
includelib C:\masm32\lib\kernel32.lib
;################################################# #########################
;################################################# #########################
;################################################# #########################
;################################################# #########################
;################################################# #########################
.data?
pszParam dd ?
hSnapshot dd ?
uProcess PROCESSENTRY32 <>
;################################################# #########################
;################################################# #########################
.code
;################################################# #########################
start: invoke GetCommandLine
mov edi, eax
xor ecx, ecx
invoke lstrlen, eax
.while ecx!=eax
.if byte ptr [edi]==" "
inc edi
mov [pszParam], edi
.break
.endif
inc ecx
inc edi
.endw
cmp ecx, eax
je done
mov [uProcess.dwSize], sizeof uProcess
invoke CreateToolhelp32Snapshot, 2, 0
mov [hSnapshot], eax
invoke Process32First, eax, ADDR uProcess
.while eax
xor ecx, ecx
lea edi, [uProcess.szExeFile]
mov ebx, edi
dec ebx
invoke lstrlen, edi
add edi, eax
.while edi!=ebx
invoke lstrcmpi, edi, [pszParam]
.if !eax
invoke OpenProcess, PROCESS_TERMINATE, 1, [uProcess.th32ProcessID]
invoke TerminateProcess, eax, 0
jmp done
.endif
; optimize this
dec edi
.endw
invoke Process32Next, [hSnapshot], ADDR uProcess
.endw
done: invoke CloseHandle, [hSnapshot]
invoke ExitProcess, eax
;################################################# #########################
end start
Run this code through MASM, and you have the power !!