首页 > 代码库 > Delphi中上指定进程(进程名)

Delphi中上指定进程(进程名)

procedure KillProcess(ExeName: string);    const      PROCESS_TERMINATE = $0001; //进程的PROCESS_TERMINATE访问权限     var      ContinueLoop: Boolean;      FSnapshotHandle: THandle;      FProcessEntry32: TProcessEntry32;    begin      //获取系统所有进程快照       FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);      //调用Process32First前用Sizeof(FProcessEntry32)填充FProcessEntry32.dwSize       FProcessEntry32.dwSize := Sizeof(FProcessEntry32);      //获取快照中第一个进程信息并保存到FProcessEntry32结构体中       ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);      while integer(ContinueLoop) <> 0 do //循环枚举快照中所有进程信息       begin        //找到要中止的进程名         if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeName))          or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeName))) then           TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),FProcessEntry32.th32ProcessID), 0);     //中止进程         ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32); //查找下一个符合条件进程       end;    end;    

  

Delphi中上指定进程(进程名)