杀死你的程序!(100分)

  • 主题发起人 主题发起人 yutao728
  • 开始时间 开始时间
Y

yutao728

Unregistered / Unconfirmed
GUEST, unregistred user!
请问 怎么查找指定的应用程序(比如:myapp.exe) 并用程序实现关闭它???
 
查找进程
 
怎么查???:((
 
以打開記事本為例﹐試了能不能馬上給我分呀。我急需。
procedure TForm1.Button1Click(Sender: TObject);
var
CommandLine,Txt: string;
bCreateProcess: boolean;
lpStartupInfo: TStartupInfo;
begin
Button1.Enabled := false;
Button2.Enabled := true;
//ÌîÈë StartupInfo
FillChar(lpStartupInfo, Sizeof(TStartupInfo), #0);
lpStartupInfo.cb := Sizeof(TStartupInfo);
lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
lpStartupInfo.wShowWindow := SW_NORMAL;

CommandLine := 'C:/Winnt/Notepad.exe';
bCreateProcess := CreateProcessA(pchar(CommandLine),nil,
nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,
lpStartupInfo, lpProcessInformation);

if bCreateProcess then
begin
//give some time for the app to initialize
WaitForInputIdle(lpProcessInformation.hProcess,60000);

memo1.clear;
memo1.Lines.Add(format(' hProcess: %d',[lpProcessInformation.hProcess]));
memo1.lines.add(format(' hThread: %d',[lpProcessInformation.hThread]));
memo1.lines.add(format('dwProcessID: %d', [lpProcessInformation.dwProcessID]));
memo1.lines.add(format(' dwThreadID: %d', [lpProcessInformation.dwThreadId]));
WndCount:=0;
//Get Thread Window
enumThreadWindows(lpProcessInformation.dwThreadID, @enumThreadWndProc, 0);
memo1.Lines.Add('----------');
//Get Child Window
enumChildWindows(wndArray[0], @enumThreadWndProc,0);
//set caption
Txt := 'Testing';
SendMessage(WndArray[0], WM_SetText, 0, LParam(pChar(Txt)));
//set text
Txt := 'This is test text';
SendMessage(EditHandle, WM_SetText, 0, LParam(pChar(Txt)));
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
PostMessage( WndArray[0], WM_Command, 28, 0);
Button1.Enabled := true;
end;
 
dadabox:
你的程序是什么呀
 
看标题好怕怕,进来一看误会了。
 
你照著貼上去﹐再加几個相應的控件呀。以進程方式加開一個記事本﹐再關閉記事本。
OK﹐再給你貼一個。加上SheppAPI,TlHelp32﹔
procedure TForm1.Button3Click(Sender: TObject);//µÃµ½µ±Ç°½ø³Ì¼°ID
var
hSnapshot: THandle;
ProcessEntry: TProcessEntry32;
hProcess: THandle;
sFileName: string;
iProcessID: Integer;
iOK:Boolean;
begin
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry.dwSize := SizeOf(TProcessEntry32);
// hProcess := Process32First(hSnapshot, ProcessEntry);
iOK := Process32First(hSnapshot, ProcessEntry);
repeat
sFileName := ExtractFileName(ProcessEntry.szExeFile);
listbox1.Items.Add(sFileName);
listbox2.Items.Add(IntToStr(ProcessEntry.th32ProcessID));
if sFileName = 'EXPLORER.EXE' then
begin
iProcessID := ProcessEntry.th32ProcessID; // ExplorerµÄProcessID
Break;
end;
until (not Process32Next(hSnapshot, ProcessEntry));
CloseHandle(hSnapshot);
end;

procedure TForm1.ListBox2Click(Sender: TObject);
var i:integer;
begin
for i:=0 to ListBox2.Items.Count-1 do
if ListBox2.Selected then
Edit1.Text:=ListBox2.Items.Strings;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
KillTask(Edit1.text);
end;

function TForm1.KillTask(ExeFileName: string): Integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop:Boolean;
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
begin
Result:=0;
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=SizeOf(FProcessEntry32);
ContinueLoop:=Process32First(FSnapShotHandle,FProcessEntry32);
while Integer(ContinueLoop)<>0 do
begin
Result:=Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FPROCESSEntry32.th32ProcessID),0));
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))=UpperCase(ExeFilename)) or (UpperCase(FProcessEntry32.szExeFile)=UpperCase(ExeFileName))) then
ContinueLoop:=Process32Next(FSnapShotHandle,FProcessEntry32);
end;
end;

你試試吧﹐要還不行﹐我就將程序發給你。不過﹐自己試最好﹐印象深刻一些。
 
dadabox:
while Integer(ContinueLoop)<>0 do
begin
Result:=Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FPROCESSEntry32.th32ProcessID),0));
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))=UpperCase(ExeFilename)) or (UpperCase(FProcessEntry32.szExeFile)=UpperCase(ExeFileName))) then
ContinueLoop:=Process32Next(FSnapShotHandle,FProcessEntry32);
end;
这段怎么老循环????????
 
如果你知道指定应用程序的标题就好办多了.
比如标题为'Kill'.
var
h: HWnd;
begin
h:=FindWindow(nil, 'Kill');
if h<>0 then
SendMessage(h, WM_Close, 0, 0);
end;
 
對不起﹐再試下面的﹐絕對沒有問題了。
procedure TForm1.Button3Click(Sender: TObject);//查出所有進程﹐
var
hSnapshot: THandle;
ProcessEntry: TProcessEntry32;
hProcess: THandle;
sFileName: string;
iProcessID: Integer;
iOK:Boolean;
begin
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry.dwSize := SizeOf(TProcessEntry32);
iOK := Process32First(hSnapshot, ProcessEntry);
repeat
sFileName := ExtractFileName(ProcessEntry.szExeFile);
listbox1.Items.Add(sFileName);//進程使用的EXE
listbox2.Items.Add(IntToStr(ProcessEntry.th32ProcessID));//進程號
if sFileName = 'EXPLORER.EXE' then
begin
iProcessID := ProcessEntry.th32ProcessID; // ExplorerµÄProcessID
Break;
end;
until (not Process32Next(hSnapshot, ProcessEntry));
CloseHandle(hSnapshot);
end;

procedure TForm1.Button5Click(Sender: TObject);//殺掉你選中的進程
begin
TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),StrToInt(Edit1.Text)),0);
end;
 
多人接受答案了。
 
如果待杀死的进程出现没有响应的现象,也能够杀死吗?
 
后退
顶部