Ver Mensaje Individual
  #3  
Antiguo 06-01-2020
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Reputación: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Cita:
Empezado por MaxiDucoli Ver Mensaje

Se pueden buscar los exe en ejecución y terminarlos directamente? Eso sería de mucha ayuda para el programa principal...

Se me olvidaba esta parte.


Se puede terminar cualquier proceso a lo bruto aunque no es lo más recomendable. Se hace con la API TerminateProcess, pero es mejor tratar de terminarlos enviando el mensaje WM_CLOSE a la ventana principal de la aplicación. Si te interesa como buscar y matar procesos a lo bruto te dejo esto que escribí hace unos años:


Código Delphi [-]
uses
  Windows, TLHelp32;

.................

function EnablePrivilege(name: String; Enable: boolean = true): boolean;
var
  hToken: Cardinal;
  priv: TOKEN_PRIVILEGES;
begin
  priv.PrivilegeCount:= 1;
  priv.Privileges[0].Attributes:= 0;
  if Enable then priv.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED;
  LookupPrivilegeValue(nil, PCHAR(name), priv.Privileges[0].Luid);
  OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken);
  AdjustTokenPrivileges (hToken, FALSE, priv, sizeof(priv), nil, PDWORD(nil)^);
  Result:= (GetLastError = ERROR_SUCCESS);
  CloseHandle (hToken);
end;

procedure KillProcess(FileName: String);
var
  Process, hSysSnapshot: THandle;
  PE: TPROCESSENTRY32;
begin
  EnablePrivilege('SeDebugPrivilege');
  PE.dwSize:= sizeof(TPROCESSENTRY32);
  hSysSnapshot:= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if (hSysSnapshot <> INVALID_HANDLE_VALUE) and Process32First(hSysSnapshot, PE) then
    repeat
      if (lstrcmpi(PE.szExeFile, PAnsiChar(FileName)) = 0) and (GetCurrentProcessID <> PE.th32ProcessID) then
      begin
        Process:= OpenProcess(PROCESS_TERMINATE, false, PE.th32ProcessID);
        if Process <> 0 then
        begin
          TerminateProcess(Process, 0);
          CloseHandle(process);
        end;
      end;
    until not Process32Next(hSysSnapshot, PE);
  CloseHandle(hSysSnapshot);
  EnablePrivilege('SeDebugPrivilege', false);
end;


Saludos.
Responder Con Cita