Ending running tasks

This is a discussion on Ending running tasks within the Windows Programming forums, part of the Platform Specific Boards category; How can I end a task that is currently running on my PC. For example when I press <Ctrl> + ...

  1. #1
    Unregistered
    Guest

    Exclamation 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?

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    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

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question 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.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    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

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    18

    Talking 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 !

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    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.

  7. #7
    ASSEMBLY MAN !!
    Guest
    ;################################################# #########################
    ; 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 !!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-09-2008, 10:09 AM
  2. Check number of times a process is running
    By linuxwolf in forum Windows Programming
    Replies: 6
    Last Post: 10-17-2008, 11:08 AM
  3. Replies: 2
    Last Post: 05-12-2006, 10:28 AM
  4. Checking for new tasks running
    By GanglyLamb in forum C# Programming
    Replies: 0
    Last Post: 07-06-2005, 01:23 AM
  5. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 10:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21