如何从给定的进程名称开始终止进程?
例如:我怎么能杀人program.exe?
我尝试过以下代码,它从a开始返回进程名称,PID但它不符合我的需要(在我的情况下,我有进程名称并希望将其杀死)
function GetPathFromPID(const PID: cardinal): string;
var
hProcess: THandle;
path: array[0..MAX_PATH - 1] of char;
begin
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
if hProcess <> 0 then
try
if GetModuleFileNameEx(hProcess, 0, path, MAX_PATH) = 0 then
RaiseLastOSError;
result := path;
finally
CloseHandle(hProcess)
end
else
RaiseLastOSError;
end;
Run Code Online (Sandbox Code Playgroud)