Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Killing/Ending/Closing a Process/Window
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
BirdsEye
Advanced Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 94

PostPosted: Mon Aug 18, 2008 11:38 am    Post subject: Killing/Ending/Closing a Process/Window Reply with quote

Hey there,
I'm new to Win32 programming and have been experimenting with a few functions such as PostMessage, FindWindow, and so on. For the past few minutes I've been trying to close a window and succeded by using FindWindow and EndTask or DestroyWindow. I came across an application which didn't have a window name and could only be ended by its process on taskmgr. How would you close the window or end the process? I tried using GetProcessId, but I really don't know what to do after that. I tried using some other functions but I didn't really know how to utilize them yet. So do you have any API suggestions? I'm going to try TerminateProcess in the mean time. How would I close or end a process by getting its PID or by closing its window (and if it doesn't have a name.)
Thanks.
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Mon Aug 18, 2008 11:47 am    Post subject: Reply with quote

If ur using a dll injection use ExitProcess(0)
If not use TerminateProcess.
Back to top
View user's profile Send private message
yoni0505
Expert Cheater
Reputation: 0

Joined: 08 Apr 2008
Posts: 110
Location: Israel

PostPosted: Mon Aug 18, 2008 11:50 am    Post subject: Reply with quote

with cmd its taskkill, i dunno if it got something to do with win32 Confused
_________________
"There is no knowledge that is not power."
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Aug 18, 2008 12:00 pm    Post subject: Reply with quote

Back when I was noob (uber noob) I remember doing it with PostMessage and WM_QUIT and another way was PostQuitMessage. I'm sure there are better ways though.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Aug 18, 2008 12:03 pm    Post subject: Reply with quote

CreateToolhelp32Snapshot() -> Process32First()/Process32Next()
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Aug 18, 2008 12:06 pm    Post subject: Reply with quote

Get the Process Id the way Flyte said, use OpenProcess with the PROCESS_TERMINATE access flag, then use TerminateProcess to the handle OpenProcess returned.
_________________
Back to top
View user's profile Send private message
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Mon Aug 18, 2008 12:07 pm    Post subject: Reply with quote

CreateRemoteThread(&ExitProcess)?
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Mon Aug 18, 2008 1:26 pm    Post subject: Reply with quote

DoomsDay wrote:
CreateRemoteThread(&ExitProcess)?


That should work too.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Mon Aug 18, 2008 2:12 pm    Post subject: Reply with quote

Follow these steps carefully or you will BSOD (joking):

To kill a process by getting its ID via Window Caption:
FindWindow -> GetWindowThreadProcessId -> OpenProcess (PROCESS_TERIMINATE access) -> TerminateProcess

To kill a process by getting its ID via looping around the snapshot list:
CreateToolhelp32Snapshot -> Process32First/Next -> Compare statement -> OpenProcess -> TerminateProcess
Back to top
View user's profile Send private message
BirdsEye
Advanced Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 94

PostPosted: Tue Aug 19, 2008 1:31 pm    Post subject: Reply with quote

Rot1 wrote:
Follow these steps carefully or you will BSOD (joking):

To kill a process by getting its ID via Window Caption:
FindWindow -> GetWindowThreadProcessId -> OpenProcess (PROCESS_TERIMINATE access) -> TerminateProcess

To kill a process by getting its ID via looping around the snapshot list:
CreateToolhelp32Snapshot -> Process32First/Next -> Compare statement -> OpenProcess -> TerminateProcess


Thanks Kasper but I'm a bit confused with choice A. I use FindWindow to get a handle on the window and then I used the returned handle in GetWindowThreadProcessId but I don't understand the second parameter. And where would I use the handle that GetWindowThreadProcessId returned? And for OpenProcess also. I'm all confused and don't understand the last param of OpenProcess. Which handle do you use in TerminateProcess? Did I mention I'm confused?... Can you please give an example? Or collaborate a bit more?
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Tue Aug 19, 2008 1:33 pm    Post subject: Reply with quote

The last parameter of op is the processID also the 2nd value from the 2nd function.

Last edited by dnsi0 on Tue Aug 19, 2008 1:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Aug 19, 2008 1:35 pm    Post subject: Reply with quote

BirdsEye wrote:
Rot1 wrote:
Follow these steps carefully or you will BSOD (joking):

To kill a process by getting its ID via Window Caption:
FindWindow -> GetWindowThreadProcessId -> OpenProcess (PROCESS_TERIMINATE access) -> TerminateProcess

To kill a process by getting its ID via looping around the snapshot list:
CreateToolhelp32Snapshot -> Process32First/Next -> Compare statement -> OpenProcess -> TerminateProcess


Thanks Kasper but I'm a bit confused with choice A. I use FindWindow to get a handle on the window and then I used the returned handle in GetWindowThreadProcessId but I don't understand the second parameter. And where would I use the handle that GetWindowThreadProcessId returned? And for OpenProcess also. I'm all confused and don't understand the last param of OpenProcess. Which handle do you use in TerminateProcess? Did I mention I'm confused?... Can you please give an example? Or collaborate a bit more?


Code:
#include <windows.h>

DWORD pID; //variable that will hold the pID

void main( void )
{
HWND hWnd = FindWindow(NULL, L"GTA: San Andreas");
GetWindowThreadProcessId(hWnd, &pID); //Gets the ID and stores it
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pID); //gets handle and access
TerminateProcess(hProcess, 0); //we aim it on the handle we got
return;
}
Back to top
View user's profile Send private message
BirdsEye
Advanced Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 94

PostPosted: Tue Aug 19, 2008 1:59 pm    Post subject: Reply with quote

Rot1 wrote:
BirdsEye wrote:
Rot1 wrote:
Follow these steps carefully or you will BSOD (joking):

To kill a process by getting its ID via Window Caption:
FindWindow -> GetWindowThreadProcessId -> OpenProcess (PROCESS_TERIMINATE access) -> TerminateProcess

To kill a process by getting its ID via looping around the snapshot list:
CreateToolhelp32Snapshot -> Process32First/Next -> Compare statement -> OpenProcess -> TerminateProcess


Thanks Kasper but I'm a bit confused with choice A. I use FindWindow to get a handle on the window and then I used the returned handle in GetWindowThreadProcessId but I don't understand the second parameter. And where would I use the handle that GetWindowThreadProcessId returned? And for OpenProcess also. I'm all confused and don't understand the last param of OpenProcess. Which handle do you use in TerminateProcess? Did I mention I'm confused?... Can you please give an example? Or collaborate a bit more?


Code:
#include <windows.h>

DWORD pID; //variable that will hold the pID

void main( void )
{
HWND hWnd = FindWindow(NULL, L"GTA: San Andreas");
GetWindowThreadProcessId(hWnd, &pID); //Gets the ID and stores it
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pID); //gets handle and access
TerminateProcess(hProcess, 0); //we aim it on the handle we got
return;
}


o.o"... My code was exactly like that except with different FindWindow paramaters. I used your code and filled accordingly but it still doesn't work o.o...
EDIT: I found out that it my mistake. After I filled out the exact Window name and made my first FindWindow param NULL, it worked. It was my fault.


Last edited by BirdsEye on Tue Aug 19, 2008 2:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Tue Aug 19, 2008 2:01 pm    Post subject: Reply with quote

are you sure you put the window name into the findwindow's 2nd parameter?

cause I made one just like it before rot1 released that one. ANd it works perfect. BTW I programed that one in delphi.
Back to top
View user's profile Send private message
BirdsEye
Advanced Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 94

PostPosted: Tue Aug 19, 2008 2:20 pm    Post subject: Reply with quote

dnsi0 wrote:
are you sure you put the window name into the findwindow's 2nd parameter?

cause I made one just like it before rot1 released that one. ANd it works perfect. BTW I programed that one in delphi.


I know, the window name I put in the second param was incorrect. I adjusted it and it worked fine. Anyways I played around with Kasper's code and got to this:

Code:

#include <windows.h>
#include <stdio.h>

DWORD pID; //variable that will hold the pID

void main( void )
{
SetConsoleTitleA("Console");

HWND hConsole = FindWindow(NULL, L"Console");
HWND hWnd = FindWindow(NULL, L"Untitled - Notepad");

if(hWnd == NULL)
{
printf("The predefined process was not detected... Exiting...\n");
Sleep(2500);
DestroyWindow(hConsole);
}

else
{
printf("Process was found... Terminating...");
Sleep(3000);
GetWindowThreadProcessId(hWnd, &pID); //Gets the ID and stores it
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pID); //gets handle and access
TerminateProcess(hProcess, 0); //we aim it on the handle we got
}

return;
}


I have no experience with simple statements and such. I just did this with common sense o.o.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites