VB icon

Detecte and close any application class

Email
Submitted on: 1/1/2015 5:52:00 PM
By: NeWNeO (from psc cd)  
Level: Intermediate
User Rating: By 4 Users
Compatibility: Delphi 7, Delphi 6, Delphi 5
Views: 1506
 
     This code read all running process on the system, and detect classname called 'Notepad' (Do you know what is this? :P) Then, it gets the Handle, and post a message for close the app.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
!**************************************
! Name: Detecte and close any application class
! Description:This code read all running process on the system, and detect classname called 'Notepad' (Do you know what is this? :P) Then, it gets the Handle, and post a message for close the app.
! By: NeWNeO (from psc cd)
!
! Inputs:Well, you need a Timer (called Timer1) and 2 labels (called Label1 and Label2).
And you must declare on "uses" "ShellApi" !
!**************************************

Function TotalAPP(HWND : Thandle; Param : Integer): BOOL; stdcall;
var
Buff, NameOfClass : array[0..255] of char;
wintext,handle,parent,clase: string;
AppHandle: cardinal;
intExitCode: integer;
begin
GetWindowText(HWND,PChar(LongInt(@Buff)),255);
GetClassName(HWND,Pchar(LongInt(@NameOfClass)),255);
WinText:=buff;
Handle:=IntToStr(LongInt(HWND));
Parent:=IntToStr(LongInt(GetParent(hwnd)));
Clase:=NameOfClass;
if clase = 'Notepad'
 then begin
 form1.label1.caption := (Wintext+' '+Handle+' '+parent+' '+nameofclass);
 Apphandle := integer(handle);
 form1.label2.caption := (handle);
 GetExitCodeprocess(AppHandle,cardinal(intExitCode));
 Postmessage(integer(Apphandle), WM_DESTROY, intExitCode, 0);
 end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Enumwindows(@TotalAPP,0);
end;


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/19/2015 2:25:44 PMDom

Error on this line :
Apphandle := integer(handle);
must be
Apphandle := strtoint(handle);
thanks for code
Dom
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.