Ver Mensaje Individual
  #3  
Antiguo 01-07-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Nipx4215,

Cita:
Empezado por Nipx4215
...Como saber si la aplicación fue ejecutada desde Delphi...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellAPI, TlHelp32, PsAPI;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetParentProcess(PID : DWORD) : String;
var
   SnapShot : THandle;
   ProcessEntry32 : TProcessEntry32;
   PPID : DWORD;
   PPHandle : THandle;
   PPPath : PChar;

begin

   SnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
   GetMem(PPPath, MAX_PATH);

   if SnapShot <> INVALID_HANDLE_VALUE then
   begin
      ProcessEntry32.dwSize := SizeOf(ProcessEntry32);
      if Process32First(SnapShot, ProcessEntry32) then
      repeat
         if ProcessEntry32.th32ProcessID = PID then
         begin
            PPID := ProcessEntry32.th32ParentProcessID;
            PPHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,PPID);
            if PPHandle <> 0 then
            begin
               GetModuleFileNameEx(PPHandle, 0, PPPath, MAX_PATH);
               Result := PPPath;
            end
            else
               Result := EmptyStr;
            CloseHandle(PPHandle);
            Break;
         end;
      until not Process32Next(SnapShot, ProcessEntry32);
      CloseHandle(SnapShot);
   end;

   FreeMem(PPPath);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   MessageDlg(GetParentProcess(GetCurrentProcessId),mtInformation,[mbOK],0);
end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Obtiene la ruta y nombre del proceso padre de la aplicación lo cual permite determinar desde donde fue ejecutada la misma, como se muestra en la siguiente imagen:



Espero sea útil

Nelson.
Responder Con Cita