| View previous topic :: View next topic |
| Author |
Message |
BirdsEye Advanced Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 94
|
Posted: Mon Aug 18, 2008 11:38 am Post subject: Killing/Ending/Closing a Process/Window |
|
|
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 |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Aug 18, 2008 11:47 am Post subject: |
|
|
If ur using a dll injection use ExitProcess(0)
If not use TerminateProcess.
|
|
| Back to top |
|
 |
yoni0505 Expert Cheater
Reputation: 0
Joined: 08 Apr 2008 Posts: 110 Location: Israel
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Mon Aug 18, 2008 12:00 pm Post subject: |
|
|
| 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 |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon Aug 18, 2008 12:03 pm Post subject: |
|
|
| CreateToolhelp32Snapshot() -> Process32First()/Process32Next()
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Aug 18, 2008 12:06 pm Post subject: |
|
|
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 |
|
 |
DoomsDay Grandmaster Cheater
Reputation: 0
Joined: 06 Jan 2007 Posts: 768 Location: %HomePath%
|
Posted: Mon Aug 18, 2008 12:07 pm Post subject: |
|
|
| CreateRemoteThread(&ExitProcess)?
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Aug 18, 2008 1:26 pm Post subject: |
|
|
| DoomsDay wrote: | | CreateRemoteThread(&ExitProcess)? |
That should work too.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Mon Aug 18, 2008 2:12 pm Post subject: |
|
|
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 |
|
 |
BirdsEye Advanced Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 94
|
Posted: Tue Aug 19, 2008 1:31 pm Post subject: |
|
|
| 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 |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Tue Aug 19, 2008 1:33 pm Post subject: |
|
|
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 |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Tue Aug 19, 2008 1:35 pm Post subject: |
|
|
| 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 |
|
 |
BirdsEye Advanced Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 94
|
Posted: Tue Aug 19, 2008 1:59 pm Post subject: |
|
|
| 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 |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Tue Aug 19, 2008 2:01 pm Post subject: |
|
|
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 |
|
 |
BirdsEye Advanced Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 94
|
Posted: Tue Aug 19, 2008 2:20 pm Post subject: |
|
|
| 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 |
|
 |
|