Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

SunShinE_mk

Function Delphi

Recommended Posts

function TForm1.TerminateProcesso(sFile: string): Bool;

var

verSystem: TOSVersionInfo;

hdlSnap,hdlProcess: THandle;

bPath,bLoop: Bool;

peEntry: TProcessEntry32;

arrPid: array [0..1023] of DWord;

iC: DWord;

k,iCount: Integer;

arrModul: array [0..299] of Char;

hdlModul: HMODULE;

begin

result:=false;

if ExtractFileName(sFile)=sFile then

bPath:=false

else

bPath:=true;

 

verSystem.dwOSVersionInfoSize:=SizeOf(TOSVersionInfo);

GetVersionEx(verSystem);

 

if verSystem.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS then

begin

hdlSnap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

peEntry.dwSize:=Sizeof(peEntry);

bLoop:=Process32First(hdlSnap,peEntry);

while integer(bLoop)<>0 do

begin

if bPath then

begin

if CompareText(peEntry.szExeFile,sFile)=0 then

begin

TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,peEntry.th32ProcessID) ,0);

result:=true;

end;

end

else

begin

if CompareText(ExtractFileName(peEntry.szExeFile),sFile)=0 then

begin

TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,peEntry.th32ProcessID) ,0);

result:=true;

end;

end;

bLoop:=Process32Next(hdlSnap,peEntry);

end;

CloseHandle(hdlSnap);

end

else

if verSystem.dwPlatformId=VER_PLATFORM_WIN32_NT then

begin

EnumProcesses(@arrPid,SizeOf(arrPid),iC);

iCount:=iC div SizeOf(DWORD);

for k:=0 to Pred(iCount) do

begin

hdlProcess:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,false,arrPid [k]);

if (hdlProcess<>0) then

begin

EnumProcessModules(hdlProcess,@hdlModul,SizeOf(hdlModul),iC);

GetModuleFilenameEx(hdlProcess,hdlModul,arrModul,SizeOf(arrModul));

if bPath then

begin

if CompareText(arrModul,sFile)=0 then

begin

TerminateProcess(OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,False,arrPid [k]), 0);

result:=true;

end;

end

else

begin

if CompareText(ExtractFileName(arrModul),sFile)=0 then

begin

TerminateProcess(OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,False,arrPid [k]), 0);

result:=true;

end;

end;

CloseHandle(hdlProcess);

end;

end;

end;

end;

 

encontrei essa na net.. e deu certo

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.