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 


[Delphi] Kill specific thread in process?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Thu Apr 24, 2008 1:33 pm    Post subject: [Delphi] Kill specific thread in process? Reply with quote

How can i "get the last thread" & "kill it" within a running process (delphi code)?

For example this can be done manualy like that:




And for another example i found in google some interesting articles but they don't give me enough information. If somebody is interested can look right here:

http://www.delphicorner.f9.co.uk/articles/db1.htm
http://www.delphicorner.f9.co.uk/articles/op1.htm

Thank you very much for your time even reading that post. Smile
I will be glad if somebody can help me with some "example of code". Thank you and have a nice day!

_________________

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

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Thu Apr 24, 2008 2:30 pm    Post subject: Reply with quote

don't forget to include (i mean add to the uses list) Tlhelp32;

edit: irwin, what about GetWindowThreadProcessId ?

edit2: you'll have to declare OpenThread from kernel32.dll yourself cause it's not added in windows.pas


Last edited by DeletedUser14087 on Thu Apr 24, 2008 2:50 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: Thu Apr 24, 2008 3:09 pm    Post subject: Reply with quote

so irwin, the code (from what i've tried now using MSDN) will look like this ?

Code:
const THREAD_TERMINATE = $0001;

Function OpenThread(
dwDesiredAccess:DWORD;
bInheritHandle:BOOL; //True or False, as in bool AKA Boolean
dwThreadId:DWORD):THandle;
external kernel32 name 'OpenThread';

Function GetExitCodeThread(
hThread:THandle;
lpExitCode:DWORD):BOOL;
external kernel32 name 'GetExitCodeThread';

procedure TForm1.Button1Click(Sender: TObject);
var h:HWND;
    OT,OP,pID:cardinal;
    EC:BOOL;
begin
h:=FindWindow(nil,'Minesweeper');
if (h<>0) then
 begin
 GetWindowThreadProcessId(h,pID);
 ShowMessage('GWTPID');
 OP:=OpenProcess(PROCESS_ALL_ACCESS,FALSE,pID);
 ShowMessage('OP');
 OT:=OpenThread(THREAD_TERMINATE,FALSE,pID);
 ShowMessage('OT');
 EC:=GetExitCodeThread(OP,OT);
 TerminateThread(OT,Cardinal(EC));
 end;
end;


Edit: Holy crap, i just noticed the topic thread, i was blind again lol

Kill a specific THREAD in a process, -.-
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Apr 24, 2008 3:44 pm    Post subject: Reply with quote

Nah, kill the last thread in a process.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Fri Apr 25, 2008 12:30 pm    Post subject: Reply with quote

Kaspersky, really nice code thought this happens @ TerminateThread(OT,Cardinal(EC));...



Code:
procedure TForm1.Button1Click(Sender: TObject);
var h:HWND;
    OT,OP,pID:cardinal;
    EC:BOOL;
begin
h:=FindWindow(nil,'MyAppCaption');
if (h<>0) then
 begin
 GetWindowThreadProcessId(h,pID);
 ShowMessage('GettingWTPID');
 OP:=OpenProcess(PROCESS_ALL_ACCESS,FALSE,pID);
 ShowMessage('Opening the process....');
 OT:=OpenThread(THREAD_TERMINATE,FALSE,pID);
 ShowMessage('Opening Thread...');
 EC:=GetExitCodeThread(OP,OT);
 TerminateThread(OT,Cardinal(EC));
 end;
end;


I think it gives that error because i have not specified which thread to be terminated or i am wrong?

Can somebody give more hints what to do and what needs to be fixed? Very Happy

Thank you all. Razz

_________________

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

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Apr 25, 2008 2:31 pm    Post subject: Reply with quote

h4c0r-BG, the reason i added those ShowMessage() is to check if it successfully passes these stages, the error is due to TerminateThread().

don't make the 2nd param Cardinal(), just point it to a variable.

remove GetWindowThreadPID() and FindWindow
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
Page 1 of 1

 
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