app kill

This is a discussion on app kill within the C++ Programming forums, part of the General Programming Boards category; i have written a program that runs some system commands and then opens another app to do something. The problem ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    64

    app kill

    i have written a program that runs some system commands and then opens another app to do something.

    The problem i have is that my program won't continue until the app is closed manually, but i am wriiting an automation program so this is a major problem.

    I know the process name, whats the easiest way to shut it down.

    Thanks

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    You could use FindWindow() and SendMessage to send a WM_QUIT message to the window...

    Code:
    #include <windows.h>
    
    // ...
    
    HWND hWindow = FindWindow(NULL, "Window Name");
    SendMessage(hWindow, WM_QUIT, 0, 0);
    If all else fails, there's always TerminateProcess()... look it up on MSDN.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    64
    thanks for the reply.

    How do i get the window name, i take it this is not the same as the process name as this did not work.

    Thanks

    Shakespeare

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    No, it's not the same as the process name... just open the Process you wish to close and record the window title.

    For example, if you wanted to close the Recycle Bin:
    Code:
    HWND hRecycle = FindWindow(NULL, "Recycle Bin");
    if (hRecycle == NULL)
        MessageBox(HWND_DESKTOP, "Failed ad FindWindow()!", "Error!", MB_ICONERROR);

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I'd use ExitProcess before I used TerminateProcess

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    ExitProcess is they "safe" way of exiting a process whereas TerminateProcess will kill an app without taking any consideration to what killing an app may do. If you want to guarantee that an app will die and you know that doing so won't cause a memory leak I actually prefer using TerminatProcess.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    64
    I tried this on the recycle bin window:

    Code:
    HWND hRecycle = FindWindow(NULL, "Recycle Bin");
    
    if (hRecycle == NULL)
        MessageBox(HWND_DESKTOP, "fail", "Error!", MB_ICONERROR);
    else
        SendMessage(hRecycle, WM_QUIT, 0, 0);
    it did not work, the recycle bin remained open. And i have also tried termainating the process but have been unable to get the exit code. it returned 0x00000000.

    Thanks.
    Last edited by Shakespeare; 02-04-2003 at 03:19 AM.

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Try sending it a WM_CLOSE instead.

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    64
    still doesn't work, any other ideas?

    thanks for your help so far guys.

  10. #10
    Registered User
    Join Date
    Jan 2002
    Posts
    64
    i forgot to say, that it definitley recognises whether the window is open or not. I just can't close it.

  11. #11
    Registered User
    Join Date
    Jan 2002
    Posts
    64
    OK it works but not with window names with spaces in.

  12. #12
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Perhaps you typed it wrong. I managed to close all sorts of windows using the method I described above.

  13. #13
    Registered User
    Join Date
    Jan 2002
    Posts
    64
    yeah sorry, i didn't fully test it.
    I tried it on the recycle bin and it didn't work. But i can close almost any other window and it works with the window i need to close so it is fine.

    Strange how it won't close the recycle bin though.

    Thanks for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. How to kill a dragon with various programming languages
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-01-2007, 12:13 PM
  3. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  4. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM

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