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
public
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.