Thread: TerminateProcess help

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    TerminateProcess help

    Hi,

    My code:

    Code:
    // error checking removed
    
    // varibles
    	HWND hWndNews;
    	DWORD dwPid, error;
    	HANDLE hNews;
    
    // process closed
            hWndNews = FindWindow(NULL, "4.32 - Build: 4969");
    	dwPid = GetWindowThreadProcessId(hWndNews, NULL);
    	hNews = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);
    	TerminateProcess(hNews, 0);
    	CloseHandle(hNews);
    I am trying to terminate another application (MFC), by getting the handle, opening a process and terminating it. I have tried sending messages to the window but it dosnt work (WM_CLOSE/WM_DESTROY).

    The handle is correct, although the dwPid contains 740 and spy++ says its 000007D0.

    Anyone know how i can fix this/close the program?

    Thanks alot,
    Jack
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Are you sure the thread you are running has PROCESS_TERMINATE rights? What does TerminateProcess return? If false, what does GetLastError return?

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Make sure the handle to the process is valid. The same applies to all other handles.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TerminateProcess
    By johnchain in forum C Programming
    Replies: 2
    Last Post: 10-29-2005, 11:55 AM
  2. How to stop a aplication
    By eletron in forum C++ Programming
    Replies: 3
    Last Post: 09-19-2004, 07:10 PM
  3. Better Version of TerminateProcess
    By golfinguy4 in forum Windows Programming
    Replies: 3
    Last Post: 02-17-2003, 02:34 AM
  4. Need a little help with TerminateProcess..
    By Velius in forum C++ Programming
    Replies: 0
    Last Post: 11-30-2001, 12:02 AM
  5. TerminateProcess fails with success
    By Steve Marchetti in forum Windows Programming
    Replies: 0
    Last Post: 11-14-2001, 02:17 PM