unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, TLHelp32, StdCtrls, ShellAPI, psapi;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Memo1: TMemo;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> procedure KillCommandProcess;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>function GetFileNameFromWindow(hw:HWND):string;<br>var<br>PidResult:LongInt;<br>Pid:Cardinal;<br>hProcess:THandle;<br>hMod:HMODULE;<br>cbNeeded:Cardinal;<br>buf:array [0..MAX_PATH] of char;<br>begin<br>ResuLt:='';<br>PidResult:=GetWindowThreadProcessId(hw,Pid);<br>if PidResult=0 then Exit;<br>hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or<br>PROCESS_VM_READ,FALSE,Pid);<br>if hProcess=0 then Exit;<br>try<br>if not EnumProcessModules(hProcess,@hMod,sizeof(hMod),cbNeeded) then Exit;<br>FillChar(buf,MAX_PATH+1,#0);<br>GetModuleFileNameEx(hProcess,hMod,buf,MAX_PATH);<br>Result:=StrPas(buf);<br>finally<br>CloseHandle(hProcess);<br>end;<br>end;<br><br>procedure TForm1.KillCommandProcess;<br>var<br> ProcessSnapShotHandle: THandle;<br> ProcessEntry: TProcessEntry32;<br> ProcessHandle: THandle;<br> Ret: BOOL;<br>begin<br> ProcessSnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> if ProcessSnapShotHandle>0 then<br> begin<br> ProcessEntry.dwSize:=SizeOf(TProcessEntry32);<br> Ret:=Process32First(ProcessSnapShotHandle, ProcessEntry);<br> while Ret do<br> begin<br> Memo1.Lines.Add(GetFileNameFromWindow(ProcessEntry.th32ProcessID));<br> Ret:=Process32Next(ProcessSnapShotHandle, ProcessEntry)<br> end;<br> CloseHandle(ProcessSnapShotHandle)<br> end<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> KillCommandProcess;<br>end;<br><br>end.