procedure KillCommandProcess(sPro:string);
var
ProcessSnapShotHandle: THandle;
ProcessEntry: TProcessEntry32;
ProcessHandle: THandle;
Ret: BOOL;
begin
ProcessSnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if ProcessSnapShotHandle>0 then
begin
ProcessEntry.dwSize:=SizeOf(TProcessEntry32);
Ret:=Process32First(ProcessSnapShotHandle, ProcessEntry);
while Ret do
begin
if LowerCase(ProcessEntry.szExeFile)=LowerCase(sPro) then //原来大小写敏感,用lowercase后就不分大小写了
begin
ProcessHandle:=OpenProcess(PROCESS_TERMINATE, False,
ProcessEntry.th32ProcessID);
if ProcessHandle>0 then
begin
TerminateProcess(ProcessHandle, 0);
CloseHandle(ProcessHandle)
end
end;
Ret:=Process32Next(ProcessSnapShotHandle, ProcessEntry)
end;
CloseHandle(ProcessSnapShotHandle)
end;
end;
在使用之前要uses TlHelp32