Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 22-11-2005
Avatar de marceloalegre
[marceloalegre] marceloalegre is offline
Miembro Premium
 
Registrado: abr 2005
Ubicación: Mar del Plata - Argentina
Posts: 448
Poder: 19
marceloalegre Va por buen camino
Exclamation Saber si un eject. esta en ejecucion?¿

Buen dia!:

Como puedo saber cuando se ejecuta digamos por ejemplo programa.exe (programa.exe es ajeno a mi o sea no puedo mandarme mensajes ni nada...)

O sea necesitaria algo donde yo pasando el nombre del ejecutable me diga si esta on no en ejecucion.

Muchas Gracias!
Responder Con Cita
  #2  
Antiguo 22-11-2005
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.269
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Haz una búsqueda en los foros sobre FindWindow; Entre los hilos encontrarás éste: Como saber si una aplicacion se esta ejecutando?
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #3  
Antiguo 22-11-2005
Avatar de marceloalegre
[marceloalegre] marceloalegre is offline
Miembro Premium
 
Registrado: abr 2005
Ubicación: Mar del Plata - Argentina
Posts: 448
Poder: 19
marceloalegre Va por buen camino
Question :(

Ese es el problema, el findwindow no me sirve porque el programa esta oculto de la lista de aplicaciones, o sea no tengo un nombre de ventana como para hacer un FindWindow(nil,'Calculadora'); ... yo lo que tengo es el nombre de mi programa programa.exe ... yo calculo que algo debe existir para encontrar el proceso... seguire buscando...


Gracias!
Responder Con Cita
  #4  
Antiguo 22-11-2005
Avatar de marceloalegre
[marceloalegre] marceloalegre is offline
Miembro Premium
 
Registrado: abr 2005
Ubicación: Mar del Plata - Argentina
Posts: 448
Poder: 19
marceloalegre Va por buen camino
Thumbs up Ya se como buscar por Ejecutable

Buscando por la red con este problema me encontre con esta Unit asi que tema solucionado! (la paso completa para que el que quiera le pueda dar utilidad a sus funcionalidades:
Código Delphi [-]
unit ProcessViewer;
interface
uses
 Windows, Dialogs, SysUtils, Classes, ShellAPI, TLHelp32, Forms;
const
 SleepForReCheck=5000;
type TProcessInfo=record
 FileName: string;
 Caption: string;
 Visible: boolean;
 Handle: DWord;
 PClass: string;
 ThreadID: DWord;
 PID: DWord;
end;

var
 DateiList,CaptionList,VisibleList,HandleList,ClassList,ThreadIdList,PIDList: TStringList;
 ProcessInfo: array of TProcessInfo;
function EnumWindowsProc(hWnd: HWND; lParam: LPARAM): Bool; stdcall;
function KillProcessByPID(PID: DWord): boolean;
function KillProcessByFileName(FileName: string; KillAll: boolean): boolean;
procedure GetProcessList;
function GetFileNameFromHandle(Handle: hwnd):string;
function IsFileActive(FileName: String): boolean;
implementation
procedure GetProcessList;
var
 i,Laenge: integer;
begin
DateiList.Clear;
HandleList.Clear;
ClassList.Clear;
CaptionList.Clear;
VisibleList.Clear;
ThreadIdList.Clear;
PIDList.Clear;
EnumWindows(@EnumWindowsProc, 0);
Laenge:=DateiList.Count;
SetLength(ProcessInfo,Laenge);
for i:=0 to Laenge-1 do
begin
 DateiList[i]:=UpperCase(DateiList[i]);
 with ProcessInfo[i] do
 begin
  FileName:=DateiList[i];
  Caption:=CaptionList[i];
  Visible:=VisibleList[i]='1';
  Handle:=StrToInt64(HandleList[i]);
  PClass:=ClassList[i];
  ThreadID:=StrToInt64(ThreadIdList[i]);
  PID:=StrToInt64(PIDList[i]);
 end;
end;
end;
function IsFileActive(FileName: String): boolean;
var
 i: integer;
begin
result:=false;
if FileName='' then exit;
GetProcessList;
FileName:=UpperCase(ExtractFileName(FileName));
for i:=0 to Length(ProcessInfo)-1 do
begin
 if Pos(FileName,ProcessInfo[i].FileName)>0 then
 begin
  result:=true;
  break;
 end;
end;
end;
function GetFileNameFromHandle(Handle: hwnd):string;
var
 PID: DWord;
 aSnapShotHandle: THandle;
 ContinueLoop: Boolean;
 aProcessEntry32: TProcessEntry32;
begin
GetWindowThreadProcessID(Handle, @PID);
aSnapShotHandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
aProcessEntry32.dwSize := SizeOf(aProcessEntry32);
ContinueLoop := Process32First(aSnapShotHandle, aProcessEntry32);
while Integer(ContinueLoop) <> 0 do
begin
 if aProcessEntry32.th32ProcessID = PID then
 begin
  result:=aProcessEntry32.szExeFile;
  break;
 end;
 ContinueLoop := Process32Next(aSnapShotHandle, aProcessEntry32);
end;
CloseHandle(aSnapShotHandle);
end;
function EnumWindowsProc(hWnd: HWND; lParam: LPARAM): Bool;
var
 Capt,Cla: array[0..255] of char;
 Datei: string;
 ident: dword;
begin
GetWindowText(hWnd, Capt, 255);
GetClassName(hwnd,Cla,255);
ThreadIdList.Add(IntToStr(GetWindowThreadProcessId(hwnd,nil)));
Datei:=GetFileNameFromhandle(hwnd);
DateiList.Add(Datei);
HandleList.Add(IntToStr(HWnd));
if IsWindowVisible(HWnd) then VisibleList.Add('1') else VisibleList.Add('0');
ClassList.Add(Cla);
CaptionList.Add(Capt);
GetWindowThreadProcessId(StrToInt(HandleList[HandleList.Count-1]),@ident);
PIDList.Add(IntToStr(ident));
Result:=true;
end;
function KillProcessByPID(PID : DWord): boolean;
var
 myhandle : THandle;
 i: integer;
begin
myhandle := OpenProcess(PROCESS_TERMINATE, False, PID);
TerminateProcess(myhandle, 0);
for i:=0 to SleepForReCheck do Application.ProcessMessages; //Genug Zeit geben
GetProcessList;
Result:=PIDList.IndexOf(IntToStr(PID))=-1;
end;
function KillProcessByFileName(FileName: string; KillAll: boolean): boolean;
var
 i: integer;
 FileFound: boolean;
begin
result:=false;
if FileName='' then exit;
FileName:=UpperCase(ExtractFileName(FileName));
result:=true;
GetProcessList;
if KillAll then
begin
 //Kill all
 FileFound:=false;
 repeat
  GetProcessList;
  FileFound:=false;
  for i:=0 to DateiList.Count-1 do
  begin
   if Pos(Filename,DateiList[i])>0 then
   begin
    FileFound:=true;
    break;
   end;
  end;
  if ithen
  begin
   if not KillProcessByPID(StrToInt64(PIDList[i])) then
   begin
    result:=false;
    exit;
   end;
  end;
 until not FileFound;
end else
begin
 //Kill one
 for i:=0 to DateiList.Count-1 do
 begin
  if Pos(Filename,DateiList[i])>0 then break;
 end;
 if ithen
 begin
  if not KillProcessByPID(StrToInt64(PIDList[i])) then
  begin
   result:=false;
   exit;
  end;
 end;
end;
end;
initialization
DateiList:=TStringList.Create;
HandleList:=TStringList.Create;
ClassList:=TStringList.Create;
CaptionList:=TStringList.Create;
VisibleList:=TStringList.Create;
ThreadIdList:=TStringList.Create;
PIDList:=TStringList.Create;
finalization
DateiList.Free;
HandleList.Free;
ClassList.Free;
CaptionList.Free;
VisibleList.Free;
ThreadIdList.Free;
PIDList.Free;
end.

Entonces sabiendo el nombre del ejecutable hacemos:

IsFileActive('PROGRAMA.EXE") then
ShowMessage('Se esta ejecutando mi programa sii!');

Fijense que tambien esta la opcion de sacar la lista de procesos, matar procesos por pid y por nombre.

Saludos!
Responder Con Cita
  #5  
Antiguo 16-11-2006
Avatar de sakuragi
sakuragi sakuragi is offline
Miembro
 
Registrado: feb 2004
Ubicación: root
Posts: 1.435
Poder: 22
sakuragi Va por buen camino
Question

Cita:
for i:=0 to DateiList.Count-1 do
begin
if Pos(Filename,DateiList[i])>0 then
begin
FileFound:=true;
break;
end;
end;
if ithen
begin
if not KillProcessByPID(StrToInt64(PIDList[i])) then
begin
result:=false;
exit;
end;
en la aparte de
Cita:
if ithen
que se supone que va ahi? ya que marca error.

saludos

gracias
__________________
OpenSuse OpenOffice.org icomputo
Responder Con Cita
  #6  
Antiguo 16-11-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 24
seoane Va por buen camino
Código PHP:
 if DateiList.Count then 
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


La franja horaria es GMT +2. Ahora son las 10:30:26.


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