Ver Mensaje Individual
  #7  
Antiguo 01-08-2017
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Perdón veo que el enlace no responde exáctamente a tu pregunta, que es como obtener el Pid de una taréa. Para obtener el Pid dado el nombre, podrías hacer:
Código Delphi [-]
function GetPidByProcessName(const ProcName: string): Integer;
  function EnumWndProc(Handle: HWND; ST: TStrings): BOOL; stdcall;
  var
    Caption: array[0..128] of Char;
  begin
    Result := True;
    SendMessage(Handle, WM_GETTEXT, Sizeof(Caption), integer(@Caption));
    ST.AddObject(Caption, TObject(Handle));
  end;
var
  TS: TStrings;
begin
  TS := TStringList.Create;
  try
    EnumWindows(@EnumWndProc, Integer(TS));
    Result := TS.IndexOf(ProcName);
    if Result <> -1 then Result := Integer(TS.Objects[Result]);
  finally
    TS.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessageFmt('Pid: %8.8x',[GetPidByProcessName('Sin título: Bloc de notas')]);
end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 01-08-2017 a las 19:48:12.
Responder Con Cita