Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 30-10-2006
locojoan locojoan is offline
Miembro
 
Registrado: mar 2004
Posts: 18
Poder: 0
locojoan Va por buen camino
simplemente quiero ver la ruta completa de un proceso.
por ejemplo en la lista de procesos sale el msnmsgr.exe que es el microsoft messenger. y quiero saber la ruta completa de ese programa.

en pocas palabras. na funcion que ingrese el nombre del proceso y me salga la ruta completa del programa.

gracias.
Responder Con Cita
  #2  
Antiguo 30-10-2006
Avatar de delphi.com.ar
delphi.com.ar delphi.com.ar is offline
Federico Firenze
 
Registrado: may 2003
Ubicación: Buenos Aires, Argentina *
Posts: 5.932
Poder: 27
delphi.com.ar Va por buen camino
No se si es la solución correcta, pero lo que he utilizado alguna vez es obtener la ruta del primer Module del proceso: http://www.clubdelphi.com/foros/showthread.php?t=28419

Saludos!
__________________
delphi.com.ar

Dedique el tiempo suficiente para formular su pregunta si pretende que alguien dedique su tiempo en contestarla.
Responder Con Cita
  #3  
Antiguo 31-10-2006
locojoan locojoan is offline
Miembro
 
Registrado: mar 2004
Posts: 18
Poder: 0
locojoan Va por buen camino
no. no es lo que estoy buscando. en realidad no creo que sea muy complicado.

gracias de todas maneras.
Responder Con Cita
  #4  
Antiguo 31-10-2006
tefots tefots is offline
Miembro
 
Registrado: feb 2005
Posts: 108
Poder: 20
tefots Va por buen camino
Cita:
Empezado por locojoan
no. no es lo que estoy buscando. en realidad no creo que sea muy complicado.

gracias de todas maneras.
pues es mas complicado de lo que parece , ya que hay que hacer varias llamadas al api.

para hacer eso , has de abrir el proceso con openprocess a través de su pid, obtener el handle y luego hacer una llamada a GetModuleFileNameEx con ese handle.

y para obtener el pid de un proceso en concreto que ya está ejecutandose , lo mejor es hacer una llamada al api que te devuelve la lista de procesos que hay en el sistema con sus pids.

la siguiente funcion , sacada de las jedi jcl (la unit JclSysInfo) hace lo que pides. (ten en cuenta que falta alguna llamada para saber si se ejecuta en xp/w2k o en w98)

Código Delphi [-]
//==================================================================================================
// Processes, Tasks and Modules
//==================================================================================================
function RunningProcessesList(const List: TStrings; FullPath: Boolean): Boolean;
  function ProcessFileName(PID: DWORD): string;
  var
    Handle: THandle;
  begin
    Result := '';
    Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
    if Handle <> 0 then
    try
      SetLength(Result, MAX_PATH);
      if FullPath then
      begin
        if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
          StrResetLength(Result)
        else
          Result := '';
      end
      else
      begin
        if GetModuleBaseNameA(Handle, 0, PChar(Result), MAX_PATH) > 0 then
          StrResetLength(Result)
        else
          Result := '';
      end;
    finally
      CloseHandle(Handle);
    end;
  end;
  function BuildListTH: Boolean;
  var
    SnapProcHandle: THandle;
    ProcEntry: TProcessEntry32;
    NextProc: Boolean;
    FileName: string;
  begin
    SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
    if Result then
    try
      ProcEntry.dwSize := SizeOf(ProcEntry);
      NextProc := Process32First(SnapProcHandle, ProcEntry);
      while NextProc do
      begin
        if ProcEntry.th32ProcessID = 0 then
        begin
          // PID 0 is always the "System Idle Process" but this name cannot be
          // retrieved from the system and has to be fabricated.
          FileName := RsSystemIdleProcess;
        end
        else
        begin
          if IsWin2k or IsWinXP then
          begin
            FileName := ProcessFileName(ProcEntry.th32ProcessID);
            if FileName = '' then
              FileName := ProcEntry.szExeFile;
          end
          else
          begin
            FileName := ProcEntry.szExeFile;
            if not FullPath then
              FileName := ExtractFileName(FileName);
          end;
        end;
        List.AddObject(FileName, Pointer(ProcEntry.th32ProcessID));
        NextProc := Process32Next(SnapProcHandle, ProcEntry);
      end;
    finally
      CloseHandle(SnapProcHandle);
    end;
  end;
  function BuildListPS: Boolean;
  var
    PIDs: array [0..1024] of DWORD;
    Needed: DWORD;
    I: Integer;
    FileName: string;
  begin
    Result := EnumProcesses(@PIDs, SizeOf(PIDs), Needed);
    if Result then
    begin
      for I := 0 to (Needed div SizeOf(DWORD)) - 1 do
      begin
        case PIDs[i] of
          0:
            // PID 0 is always the "System Idle Process" but this name cannot be
            // retrieved from the system and has to be fabricated.
            FileName := RsSystemIdleProcess;
          2:
            // On NT 4 PID 2 is the "System Process" but this name cannot be
            // retrieved from the system and has to be fabricated.
            if IsWinNT4 then
              FileName := RsSystemProcess
            else
              FileName := ProcessFileName(PIDs[i]);
          8:
            // On Win2K PID 8 is the "System Process" but this name cannot be
            // retrieved from the system and has to be fabricated.
            if IsWin2k or IsWinXP then
              FileName := RsSystemProcess
            else
              FileName := ProcessFileName(PIDs[i]);
        else
          FileName := ProcessFileName(PIDs[i]);
        end;
        if FileName <> '' then
          List.AddObject(FileName, Pointer(PIDs[i]));
      end;
    end;
  end;
begin
  if GetWindowsVersion in [wvWinNT31, wvWinNT35, wvWinNT351, wvWinNT4] then
    Result := BuildListPS
  else
    Result := BuildListTH;
end;

solo tendrias que llamar a RunningProceslist (lista,true)
y te devolveria la lista de procesos , con sus paths , luego tendrias que hacer un extractfilepath , para sacar su ruta.

saludos.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Sobre la ruta completa de un EXE oscjae API de Windows 6 25-07-2006 12:36:15
ruta de un archivo ddd_ddd Varios 1 07-06-2006 23:08:34
Obtener ruta completa pepecharlie67 Varios 4 02-01-2006 15:25:39
Ruta de instalación Eolo SQL 0 24-08-2004 16:06:17
¿Siempre hay que poner la ruta completa de la base de datos que está en el servidor? Al González Firebird e Interbase 2 12-05-2004 22:06:25


La franja horaria es GMT +2. Ahora son las 02:45:13.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi