Como fechar um determinado aplicativo
18/02/2006
0
fazer uma verificação na memoria para ver se o aplicativo está aberto e fecha-lo
tipo:
clincando Ctrl + Alt + Del => processos => selecionar o aplicativo e clicar em Finalizar processo.
Fabiano Góes
Posts
18/02/2006
Marcelo.l
Tente usar a seguinte função:
function TerminateEXE(sFile: string): Bool; var verSystem: TOSVersionInfo; hdlSnap, hdlProcess: THandle; bPath, bLoop: Bool; peEntry: TProcessEntry32; arrPid: array[0..1023] of DWord; iC: DWord; i, 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 i := 0 to Pred(iCount) do begin hdlProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, arrPid[i]); 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[i]), 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[i]), 0); result := True; end; end; CloseHandle(hdlProcess); end; end; end; end;
Como exemplo :
if TerminateEXE(´notepad.exe´) then showmessage(´funcionou!!!´);
Se vc abrir varias instâncias do bloco de notas vai perceber que ele irá fechar todas!!!
Espero ter ajudado.
20/02/2006
Fabiano Góes
primeiro gostaria de agracer pela atenção,
Bom esta dando alguns erros, e não sei se devo declarar alguma biblioteca no uses da inha Unit .
os erros são o seguinte :
Undeclared identifier: TProcesEntry32
Undeclared identifier: CreateToolhelp32Snapshot;
Undeclared identifier: Process32First;
Undeclared identifier: Process32Next;
Undeclared identifier: EnumProcesses;
Undeclared identifier: GetModuleFilenameEx;
Se vc puder me dar mais uma ajuda eu agradeço muito !!!!
Valeu !!!!!
20/02/2006
Marco Salles
descuple , nesse caso a uses Registry não e necessária
Clique aqui para fazer login e interagir na Comunidade :)