CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2005
    Location
    Hong Kong
    Posts
    103

    Question How to close the exe program?

    I know by using ShellExecute, we can execute the exe program. On the other hand, if we want to kill the program by programming code, how to do?

  2. #2
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: How to close the exe program?

    Which process you want to kill?
    Was that process created by you? That means if you have HANDLE to that process you can use TerminateProcess (NOT recommened!).

    If you wish to terminate a Windows Application (that has window), you can use FindWindow[Ex] to find the window handle and then ask the process by sending WM_DESTROY message to the main window. If you already have HWND of the main window of the process you want to terminate, just send the WM_DESTROY message to it.

    When you terminate using WM_DESTORY, the process is given a chance to save its data and state and may also ignore the termination request. From "Applications" tab of task manager, when you click "End Task" this method is used by TM.

    When you issue "End Process" from "Processes" tab, TerminateProcess is issued.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  3. #3
    Join Date
    Aug 2005
    Posts
    104

    Re: How to close the exe program?

    Do you mean WM_CLOSE, instead of WM_DESTROY?

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: How to close the exe program?

    Ohh yes, my mistake... It is WM_CLOSE message.

    Actually, I was confused with CloseWindow API, that does minimizes the window...
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #5
    Join Date
    Apr 2005
    Location
    Hong Kong
    Posts
    103

    Red face Re: How to close the exe program?

    Sorry, i don't know how WM_CLOSE work. Actually, i am not gonna to close the present window. My meaning is, i have another program now running, for example "program1.exe". I want to kill it by another program "program2.exe" by push a button. But program2 still running. How to do?

  6. #6
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

    Re: How to close the exe program?

    Take a look at Message Sender. It is based upon the concept provied by Ajay Vijay.

  7. #7
    Join Date
    May 2005
    Posts
    4,954

    Re: How to close the exe program?

    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  8. #8
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    Re: How to close the exe program?

    My meaning is, i have another program now running, for example "program1.exe". I want to kill it by another program "program2.exe" by push a button. But program2 still running. How to do?
    If u want to kill process just like Taskmanager EndTask then u can use the following set of APIs aswell.
    Code:
    EnumProcesses
    OpenProcess
    EnumProcessModules
    GetModuleBaseName
    TerminateProcess
    Hope this will helps u.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured