urif
asked on
terminate all open applications
ok, this was already asked in https://www.experts-exchange.com/questions/20083127/getting-this-code-to-work.html
but no answer there.
when you load that code delphi complains about PTaskEntry, and i can't seem to find any referece to it anywhere.
anyway, what i need is to close all open applications on the dektop (not ALL app in the system), meaning that if i have notepad, mozilla, thunderbird and word i want to close those 4 programs.
the code i found that supposedly do that is as follow:
Q: How do I terminate all running tasks?
A: Below is some code that will help if you want to terminate ALL tasks,
no questions asked.
A word of caution, before you run this for the first time, make sure
that you save it and anything else that may have some pending data.
procedure TForm1.ButtonKillAllClick( Sender: TObject);
var
pTask : PTaskEntry;
Task : Bool;
ThisTask: THANDLE;
begin
GetMem (pTask, SizeOf (TTaskEntry));
pTask^.dwSize := SizeOf (TTaskEntry);
Task := TaskFirst (pTask);
while Task do
begin
if pTask^.hInst = hInstance then
ThisTask := pTask^.hTask
else
TerminateApp (pTask^.hTask, NO_UAE_BOX);
Task := TaskNext (pTask);
end;
TerminateApp (ThisTask, NO_UAE_BOX);
end;
can anyone give me a good code example on how to close all the open applications?
thanks so much
but no answer there.
when you load that code delphi complains about PTaskEntry, and i can't seem to find any referece to it anywhere.
anyway, what i need is to close all open applications on the dektop (not ALL app in the system), meaning that if i have notepad, mozilla, thunderbird and word i want to close those 4 programs.
the code i found that supposedly do that is as follow:
Q: How do I terminate all running tasks?
A: Below is some code that will help if you want to terminate ALL tasks,
no questions asked.
A word of caution, before you run this for the first time, make sure
that you save it and anything else that may have some pending data.
procedure TForm1.ButtonKillAllClick(
var
pTask : PTaskEntry;
Task : Bool;
ThisTask: THANDLE;
begin
GetMem (pTask, SizeOf (TTaskEntry));
pTask^.dwSize := SizeOf (TTaskEntry);
Task := TaskFirst (pTask);
while Task do
begin
if pTask^.hInst = hInstance then
ThisTask := pTask^.hTask
else
TerminateApp (pTask^.hTask, NO_UAE_BOX);
Task := TaskNext (pTask);
end;
TerminateApp (ThisTask, NO_UAE_BOX);
end;
can anyone give me a good code example on how to close all the open applications?
thanks so much
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hypoviax
ok, the code works great, a little TOO great.
it closes all the application on the desktop, but also all the tray applications that are run from the start menu, the registry and other autorun options.
any way to limit the closing of the applications to those on the desktop ONLY?
may take the name of the apps running by scanning the taskbar?
thanks again
ok, the code works great, a little TOO great.
it closes all the application on the desktop, but also all the tray applications that are run from the start menu, the registry and other autorun options.
any way to limit the closing of the applications to those on the desktop ONLY?
may take the name of the apps running by scanning the taskbar?
thanks again
Hi,
I've been away for the past few days. Will check it out tommorow.
Regards,
Hypoviax
I've been away for the past few days. Will check it out tommorow.
Regards,
Hypoviax
ASKER
thanks
Acutally, over the next few days i will try and look. I'm just starting uni so it's a bit busy at the moment. If you can wait around i'll post as soon as possible
ASKER
sure, but again this is my question:
i need to close all open applucations "on th desktop", those that are actually showing on the taskbar.
thanks
i need to close all open applucations "on th desktop", those that are actually showing on the taskbar.
thanks
I'm not sure if this would work but you could try to do a complete enumeration of windows and close all. This effectively will close the applications:
Code. You need a list view called listwindow:
Function EnumWindowsProc(
hwnd:HWND;//handle to parent window
lParam:LPARAM // Application defined value
):Boolean;stdcall;
var
{p,} buffer{, v}:pchar;
listitem:tlistitem;
Begin
result:=false;
try
//reserve a string space
Getmem(buffer,1000);
getwindowtext(hwnd,buffer, 1000);
listitem:=form1.listwindow s.Items.Ad d ;
listitem.caption:=buffer;
if length(listitem.caption)=0 then
begin
listitem.Delete ;
end;
result:=true;
//free the string space
freemem(buffer, 1000);
except
end;
end;
procedure TForm1.killspawnedapps;
var X:integer;
begin
For X:=0 to listwindow.items.count-1 do
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
enumwindows(@EnumWindowsPr oc,0);
killspawnedapps ; //The procedure to kill all applications
end;
end.
Code. You need a list view called listwindow:
Function EnumWindowsProc(
hwnd:HWND;//handle to parent window
lParam:LPARAM // Application defined value
):Boolean;stdcall;
var
{p,} buffer{, v}:pchar;
listitem:tlistitem;
Begin
result:=false;
try
//reserve a string space
Getmem(buffer,1000);
getwindowtext(hwnd,buffer,
listitem:=form1.listwindow
listitem.caption:=buffer;
if length(listitem.caption)=0
begin
listitem.Delete ;
end;
result:=true;
//free the string space
freemem(buffer, 1000);
except
end;
end;
procedure TForm1.killspawnedapps;
var X:integer;
begin
For X:=0 to listwindow.items.count-1 do
end;
procedure TForm1.Button1Click(Sender
begin
enumwindows(@EnumWindowsPr
killspawnedapps ; //The procedure to kill all applications
end;
end.
sorry i accidently pressed enter (after pressing tab)
this should be the code:
Function EnumWindowsProc(
hwnd:HWND;//handle to parent window
lParam:LPARAM // Application defined value
):Boolean;stdcall;
var
{p,} buffer{, v}:pchar;
listitem:tlistitem;
Begin
result:=false;
try
//reserve a string space
Getmem(buffer,1000);
getwindowtext(hwnd,buffer, 1000);
listitem:=form1.listwindow s.Items.Ad d ;
listitem.caption:=buffer;
if length(listitem.caption)=0 then
begin
listitem.Delete ;
end;
result:=true;
//free the string space
freemem(buffer, 1000);
except
end;
end;
procedure TForm1.killspawnedapps;
var X:integer;
begin
For X:=0 to listwindows.items.count-1 do
begin
postmessage(findwindow(nil ,pchar(lis twindows.i tem.item[x ].caption) ),wm_close ,0,0);
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
enumwindows(@EnumWindowsPr oc,0);
killspawnedapps ; //The procedure to kill all applications
end;
end.
this should be the code:
Function EnumWindowsProc(
hwnd:HWND;//handle to parent window
lParam:LPARAM // Application defined value
):Boolean;stdcall;
var
{p,} buffer{, v}:pchar;
listitem:tlistitem;
Begin
result:=false;
try
//reserve a string space
Getmem(buffer,1000);
getwindowtext(hwnd,buffer,
listitem:=form1.listwindow
listitem.caption:=buffer;
if length(listitem.caption)=0
begin
listitem.Delete ;
end;
result:=true;
//free the string space
freemem(buffer, 1000);
except
end;
end;
procedure TForm1.killspawnedapps;
var X:integer;
begin
For X:=0 to listwindows.items.count-1 do
begin
postmessage(findwindow(nil
end;
end;
procedure TForm1.Button1Click(Sender
begin
enumwindows(@EnumWindowsPr
killspawnedapps ; //The procedure to kill all applications
end;
end.
I don't really know how to do what you specifically asked, i only hope that the code above works the way you wanted
ASKER
well, we are pretty much in the same problem, the difference is that the code you post in the beginning closes all apps (and i mean ALL) without asking, the code you posted now does the same, it closes ALL app, services, etc but asking, so there;s the annoying "save" and "not responding" dialogs that the programs show.
isn't there a way to close ONLY those applications on the desktop? no the sevices, no those running on the tray area, sort of line a minimize all but close them instead of minimize them.
isn't there a way to close ONLY those applications on the desktop? no the sevices, no those running on the tray area, sort of line a minimize all but close them instead of minimize them.
ASKER
by the way i tried the approach of enumarating all the windows and then closing those that are on the desktop, but i can;t find a way to know for certain which app is running on the desktop. that's why i came here for an answer.,
also, since MOST applications that me and the people around me start are not started from the explorer, no onw uses explorer here, only the command line, and oher shells.
do you know if the enumaration has a field that tells you where the application resides?
or maybe, is there any api to talk to the taskbar? maybe we can get info from the taskbar as to what applications are running there
also, since MOST applications that me and the people around me start are not started from the explorer, no onw uses explorer here, only the command line, and oher shells.
do you know if the enumaration has a field that tells you where the application resides?
or maybe, is there any api to talk to the taskbar? maybe we can get info from the taskbar as to what applications are running there
ASKER
another way is to maybe try the link i 1st posted and try to figure where this (PTaskEntry) is declared
ASKER
how about this:
To enumerate the system's top-level windows, use the EnumWindows API
function.
EnumWindows will tell you about many more windows than you actually
want. TO check if a program has a corresponding button on the taskbar. , you need to look
at the window's extended style. Retreive that with GetWindowLong. Use
bitwise arithmetic to check for the right combination of
ws_ex_ToolWindow and ws_ex_AppWindow styles
now, i am trying this, so far no luck, then again. i am a c programmer. maybe you can try it
To enumerate the system's top-level windows, use the EnumWindows API
function.
EnumWindows will tell you about many more windows than you actually
want. TO check if a program has a corresponding button on the taskbar. , you need to look
at the window's extended style. Retreive that with GetWindowLong. Use
bitwise arithmetic to check for the right combination of
ws_ex_ToolWindow and ws_ex_AppWindow styles
now, i am trying this, so far no luck, then again. i am a c programmer. maybe you can try it
ASKER
ok, here's the code to get all apps running on the desktop, now how to close them:
function GetText(Wnd: HWND): string;
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0 then Result := ''
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
begin
Result := True;
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
Form1.Listbox1.Items.Add(' Handle: ' + IntToStr(Wnd) + ',Text: ' + GetText(Wnd));
end;
procedure TForm1.Button1Click(Sender : TObject);
var
Param: Longint;
begin
EnumWindows(@EnumWindowsPr oc, Param);
end;
function GetText(Wnd: HWND): string;
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0 then Result := ''
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
begin
Result := True;
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
Form1.Listbox1.Items.Add('
end;
procedure TForm1.Button1Click(Sender
var
Param: Longint;
begin
EnumWindows(@EnumWindowsPr
end;
ASKER
ok, if you add this
postmessage(findwindow(nil ,pchar(Get Text(Wnd)) ),wm_close ,0,0);
instead of
Form1.Listbox1.Items.Add(' Handle: ' + IntToStr(Wnd) + ',Text: ' + GetText(Wnd));
on EnumWindowsProc() it'l close the windows.
now, if you do it from the command line it won't work... weirds.
please try it
postmessage(findwindow(nil
instead of
Form1.Listbox1.Items.Add('
on EnumWindowsProc() it'l close the windows.
now, if you do it from the command line it won't work... weirds.
please try it
ok, i'll try it out today (i'm operating on a different time zone)
Regards,
Hypoviax
Regards,
Hypoviax
What i am thinking is to try to extract the PID or the actual application exename from the windows and then terminate using my earlier code
OK try this:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
ListBox3: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetText(Wnd: HWND): string;
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0 then Result := ''
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
Var pID,hProcess:DWord;
begin
Result := True;
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
Form1.Listbox1.Items.Add(I ntToStr(Wn d)); //only for display
form1.ListBox3.Items.add(G etText(Wnd )); //only for display
GetWindowThreadProcessId(W nd,@pID); //find the PID from the Wnd
form1.ListBox2.Items.add(i nttostr(pI D)); //yonly for display
hProcess:=OpenProcess(PROC ESS_TERMIN ATE,TRUE,p ID); //kill the program
TerminateProcess(hProcess, 1);//kill the program
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
var
Param: Longint;
X:Integer;
sz:pchar ;
begin
EnumWindows(@EnumWindowsPr oc, Param);
end;
end.
Regards,
Hypoviax
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
ListBox3: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetText(Wnd: HWND): string;
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0 then Result := ''
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
Var pID,hProcess:DWord;
begin
Result := True;
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
Form1.Listbox1.Items.Add(I
form1.ListBox3.Items.add(G
GetWindowThreadProcessId(W
form1.ListBox2.Items.add(i
hProcess:=OpenProcess(PROC
TerminateProcess(hProcess,
end;
end;
procedure TForm1.Button1Click(Sender
var
Param: Longint;
X:Integer;
sz:pchar ;
begin
EnumWindows(@EnumWindowsPr
end;
end.
Regards,
Hypoviax
Please note when i ran it i commented the kill program part. If that doesn't work it is easy to fix
ASKER
still doesn't work from the command line. it just kills the cmd.exe and that's it.
it's important that it works from the command line.,
working as a GUI application, well, that part i have, i posted it here, but...
it's important that it works from the command line.,
working as a GUI application, well, that part i have, i posted it here, but...
Ok, try this:
function GetText(Wnd: HWND): string;
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0 then Result := ''
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
Var pID,hProcess:DWord;
begin
Result := True;
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
Form1.Listbox1.Items.Add(I ntToStr(Wn d)); //only for display
form1.ListBox3.Items.add(G etText(Wnd )); //only for display
GetWindowThreadProcessId(W nd,@pID); //find the PID from the Wnd
form1.ListBox2.Items.add(i nttostr(pI D)); //yonly for display
hProcess:=OpenProcess(PROC ESS_TERMIN ATE,TRUE,p ID); //kill the program
TerminateProcess(hProcess, 1);//kill the program
end;
end;
function KillTask(ExeFileName: string): integer; //used to kill a process
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHa ndle,
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileNam e(FProcess Entry32.sz ExeFile)) =
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32 .szExeFile ) =
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(O penProcess (
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32Proces sID), 0));
ContinueLoop := Process32Next(FSnapshotHan dle,
FProcessEntry32);
end;
CloseHandle(FSnapshotHandl e);
end;
function FindPID(ExeFileName: string): integer; //used to find the pid of an app
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHa ndle,
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileNam e(FProcess Entry32.sz ExeFile))= UpperCase( ExeFileNam e))
or (UpperCase(FProcessEntry32 .szExeFile ) =
UpperCase(ExeFileName))) then
begin
Result :=FProcessEntry32.th32Proc essID
end;
ContinueLoop := Process32Next(FSnapshotHan dle,
FProcessEntry32);
end;
CloseHandle(FSnapshotHandl e);
end;
procedure tform1.killspawnedapps ; //kill all applications
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOLEAN;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(T H32CS_SNAP PROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHa ndle,FProc essEntry32 );
while integer(ContinueLoop) <> 0 do
begin
if FProcessEntry32.th32Parent ProcessID= FindPID('c md.exe') then //if opened by cmd.exe then terminate it
begin
killtask(FProcessEntry32.s zExeFile);
end;
ContinueLoop := Process32Next(FSnapshotHan dle,FProce ssEntry32) ;
end;
CloseHandle(FSnapshotHandl e);
end;
procedure TForm1.Button1Click(Sender : TObject); //kill the apps
var
Param: Longint;
X:Integer;
sz:pchar ;
begin
EnumWindows(@EnumWindowsPr oc, Param); //kill normal desktop apps
killspawnedapps ; //kill cmd apps
end;
Regards,
Hypoviax
function GetText(Wnd: HWND): string;
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0 then Result := ''
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
Var pID,hProcess:DWord;
begin
Result := True;
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
Form1.Listbox1.Items.Add(I
form1.ListBox3.Items.add(G
GetWindowThreadProcessId(W
form1.ListBox2.Items.add(i
hProcess:=OpenProcess(PROC
TerminateProcess(hProcess,
end;
end;
function KillTask(ExeFileName: string): integer; //used to kill a process
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHa
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileNam
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(O
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32Proces
ContinueLoop := Process32Next(FSnapshotHan
FProcessEntry32);
end;
CloseHandle(FSnapshotHandl
end;
function FindPID(ExeFileName: string): integer; //used to find the pid of an app
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHa
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileNam
or (UpperCase(FProcessEntry32
UpperCase(ExeFileName))) then
begin
Result :=FProcessEntry32.th32Proc
end;
ContinueLoop := Process32Next(FSnapshotHan
FProcessEntry32);
end;
CloseHandle(FSnapshotHandl
end;
procedure tform1.killspawnedapps ; //kill all applications
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOLEAN;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(T
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHa
while integer(ContinueLoop) <> 0 do
begin
if FProcessEntry32.th32Parent
begin
killtask(FProcessEntry32.s
end;
ContinueLoop := Process32Next(FSnapshotHan
end;
CloseHandle(FSnapshotHandl
end;
procedure TForm1.Button1Click(Sender
var
Param: Longint;
X:Integer;
sz:pchar ;
begin
EnumWindows(@EnumWindowsPr
killspawnedapps ; //kill cmd apps
end;
Regards,
Hypoviax
ASKER
thanks for the help.
but again, since i have different ways to start an application, not only explorer, or cmd but also a custom wirtten shell and the total commander and etc, etc. i can't just one function per program since i don't know what will be in the future.
so it has to be a generic, like the code i wrote above.
your alst code works great, but it did not kill those applications spawned by the custom shell.
that's why i focused on the fact that since an app has a button on the taskbar it can be killed. no matter what application spawned it.
but again, since i have different ways to start an application, not only explorer, or cmd but also a custom wirtten shell and the total commander and etc, etc. i can't just one function per program since i don't know what will be in the future.
so it has to be a generic, like the code i wrote above.
your alst code works great, but it did not kill those applications spawned by the custom shell.
that's why i focused on the fact that since an app has a button on the taskbar it can be killed. no matter what application spawned it.
ASKER
thanks for the code it works great, but since i opened the binary from the command line it didn't kill it (the form with the button in it)
now, question tho, if i run an application that has this code inside from the tray area and it starts when windows starts (either from the registry or from the start menu), will it kill itself when i close all apps?
thanks again, the points are yours.