我正在使用這個m ethodology關閉瀏覽器選項卡。如您所知,Chrome和Iexplorer爲每個選項卡使用不同的進程。我找到進程名稱並殺死它們。在下面的代碼中,爲內存中的chrome或iexplore或任何你想要的內容殺死所有進程。不要忘記在你的使用線上添加winapi.tlhelp32單元。
function KillTask(ExeFileName: string): Integer;
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(FSnapshotHandle, FProcessEntry32);
// find all process and kill them all one by one
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(
OpenProcess(PROCESS_TERMINATE,
BOOL(0),
FProcessEntry32.th32ProcessID),
0));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
這不取決於瀏覽器嗎? –
這聽起來像一個可怕的程序。當然,你想使用代理? –
我明白你想達到的目標,但我認爲這不是一個好辦法。 –