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 05-07-2007
mensana mensana is offline
Miembro
 
Registrado: sep 2006
Posts: 69
Poder: 18
mensana Va por buen camino
Cita:
Empezado por l30
... hice lo que me dijiste, pero no me funciono .
El código era para ejecutarlo en la aplicación que interactua con el desktop, es decir, la que arranca el servicio (en tu caso Notepad.exe), así que no te servirá.

Ojo: He leído que en Windows Vista se ha cerrado la posibilidad que un servicio pueda ejecutar una aplicación.
Responder Con Cita
  #2  
Antiguo 06-07-2007
l30 l30 is offline
Miembro
 
Registrado: jun 2007
Posts: 36
Poder: 0
l30 Va por buen camino
Gracias

Gracias mensana, no sabia que Windows Vista avía cerrado la posibilidad de que un servicio pueda ejecutar una aplicación, bueno entonces e decidido pasar todo el código para el servicio y me pasa lo siguiente, le digo que me muestre una listado da las aplicaciones que están corriendo en mi maquina cada cierto tiempo.

Este es el listado que me muestra:

CSRSS.EXE TPUtilWindow 2240
SVCHOST.EXE HidPhoneNotifClass 816
CSRSS.EXE TPUtilWindow 2240
SVCHOST.EXE Tapi32WndClass 816

Entonces cuando le pongo al servicio que interactué con el sistema, me da el listado real, de las aplicaciones que están corriendo, pero no quiero que mi servicio interactué con el sistema.

Que puedo hacer para resolver este problema, por si es de ayuda, paso el código que me da, las aplicaciones que están corriendo en ese momento.

Gracias por adelantado.
***********************************************************************
Código Delphi [-]
unit Unit7;

interface
uses
 Windows, Dialogs, SysUtils, Classes, ShellAPI, TLHelp32, Forms, PsApi;
const
 SleepForReCheck=5000;
type TProcessInfo=record
 FileName: string;
 Caption: string;
 Visible: boolean;
 Handle: DWord;
 PClass: string;
 ThreadID: DWord;
 PID: DWord;
end;
 TProcessInfo2= array of TProcessInfo;    
var
 DateiList,CaptionList,VisibleList,HandleList,ClassList,ThreadIdList,PIDList: TStringList;
 ProcessInfo: TProcessInfo2;
 contador67: byte;
 cantidad:integer;
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;
function GetProcessName(ProcessId: DWORD): String;
implementation

uses Unit1;

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]);
               // cantidad de tipos metidos dentro del arreglo
               cantidad:=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));
   inc(contador67);
   if contador67 >=10 then
      begin
         Sleep(1);
         contador67:=0
      end;
      
   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;

function GetProcessName(ProcessId: DWORD): String;
var
  Process: THANDLE;
  Buffer: array[0..MAX_PATH] of Char;
begin
// ejemplo esta funcion se usa haci
// GetProcessName(PID));

  Process := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, FALSE,
    ProcessId);
  if (Process<>0) then
    begin
      if (GetModuleFileNameEx(Process, 0, Buffer,Sizeof(Buffer)-1)>0) then
        Result:= String(PChar(@Buffer));
      CloseHandle(Process);
    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.

Última edición por l30 fecha: 06-07-2007 a las 05:36:13.
Responder Con Cita
  #3  
Antiguo 09-07-2007
l30 l30 is offline
Miembro
 
Registrado: jun 2007
Posts: 36
Poder: 0
l30 Va por buen camino
Ayuda

Por favor que alguien me ayude...????
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
3D Desktop TouchScreen Onti La Taberna 2 06-04-2007 12:11:34
Database Desktop? gandalf_27 C++ Builder 3 12-05-2006 22:37:51
Problemas con el DeskTop lgarcia Varios 5 11-04-2005 16:04:04
Inetrbase Desktop StartKill Firebird e Interbase 0 14-12-2004 16:11:07
Service y Application Service Ezecool Varios 0 30-09-2003 18:48:30


La franja horaria es GMT +2. Ahora son las 09:24:53.


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