Club Delphi  
    Paypal   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

 
 
Herramientas Buscar en Tema Desplegado
  #6  
Antiguo 01-11-2008
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Poder: 22
cHackAll Va por buen camino
Cita:
Empezado por aeff Ver Mensaje
a ver si capté algo, me sugieres que la cosa puede venir por "CreateToolhelp32Snapshot"??
Código Delphi [-]
uses TlHelp32;
 
//...
 
function GetParentPID(dwProcessId: Cardinal): Cardinal;
var
 ProcessEntry32: TProcessEntry32;
 hSnapshot: Cardinal;
begin
 Result := 0;
 hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 if hSnapshot <> INVALID_HANDLE_VALUE then
  begin
   if Process32First(hSnapshot, ProcessEntry32) then
    repeat
     if ProcessEntry32.th32ProcessID = dwProcessId then
      begin
       Result := ProcessEntry32.th32ParentProcessID;
       Break;
      end;
    until not Process32Next(hSnapshot, ProcessEntry32);
   CloseHandle(hSnapshot);
  end;
end;

Aunque ahora que lo pienso un poco mejor:

Código Delphi [-]
//...
 
function NtQueryInformationProcess(ProcessHandle, ProcessInformationClass: Cardinal; ProcessInformation: Pointer; ProcessInformationLength: Cardinal; ReturnLength: PCardinal): Cardinal; stdcall external 'ntdll';
 
function GetParentPID(dwProcessId: Cardinal): Cardinal;
var
 hProcess: Cardinal;
 ProcessBasicInformation: record
  ExitStatus, PebBaseAddress, AffinityMask, BasePriority, UniqueProcessId, InheritedFromUniqueProcessId: Cardinal;
 end;
begin
 Result := 0;
 hProcess := OpenProcess(PROCESS_QUERY_INFORMATION, False, dwProcessId);
 if hProcess <> 0 then
  begin
   if NtQueryInformationProcess(hProcess, 0, @ProcessBasicInformation, SizeOf(ProcessBasicInformation), nil) = 0 then
    Result := ProcessBasicInformation.InheritedFromUniqueProcessId;
   CloseHandle(hProcess);
  end;
end;

Para luego:

Código Delphi [-]
function GetProcessImageFileNameA(hProcess: Cardinal; lpImageFileName: PChar; nSize: Cardinal): Cardinal; stdcall external 'psapi';
 
procedure TForm1.Button1Click(Sender: TObject);
var
 dwProcessId, hProcess: Cardinal;
 FileName: array [1..MAX_PATH] of Char;
begin
 dwProcessId := GetParentPID(666);
 if dwProcessId <> 0 then
  begin
   hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_TERMINATE, False, dwProcessId);
   if hProcess <> 0 then
    begin
     GetProcessImageFileNameA(hProcess, @FileName, SizeOf(FileName));
     if LowerCase(ExtractFileName(PChar(@FileName))) = 'delphi32.exe' then
      TerminateProcess(hProcess, 0); // por ejemplo
     CloseHandle(hProcess);
    end;
  end;
end;

end.

Saludos
__________________
RTFM > STFW > Foro > Truco > Post > cHackAll > KeBugCheckEx
Responder Con Cita
 



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
Aplicacion en Delphi 6 ejecutada por Internet canelita Internet 1 10-07-2008 16:29:07
Cómo cerrar otra aplicacion desde mi aplicacion en Delphi 7 Gaby123 API de Windows 5 04-01-2007 22:44:51
saber la ip de una URL (desde delphi) User_baja1 Internet 4 13-09-2005 12:30:53
¿Cómo puedo saber desde mi aplicación cuándo se abre por primera vez? nuri Varios 7 21-07-2005 14:07:51
Detectar aplicacion a ser ejecutada. anitra_cattivo API de Windows 7 05-11-2004 18:52:41


La franja horaria es GMT +2. Ahora son las 23:34:47.


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