RE:Ejecutar otra aplicación.
Añade 'ShellApi' en el uses de tu form
procedure TForm1.Button1Click(Sender: TObject);
procedure RunAndWaitShell(Ejecutable,
Argumentos:string
;Visibilidad:integer);
var
Info:TShellExecuteInfo;
pInfo:PShellExecuteInfo;
exitCode:DWord;
begin
{Puntero a Info}
{Pointer to Info}
pInfo:=@Info;
{Rellenamos Info}
{Fill info}
with Info do
begin
cbSize:=SizeOf(Info);
fMask:=SEE_MASK_NOCLOSEPROCESS;
wnd:=Handle;
lpVerb:=nil;
lpFile:=PChar(Ejecutable);
{Parametros al ejecutable}
{Executable parameters}
lpParameters:=Pchar(Argumentos+#0);
lpDirectory:=nil;
nShow:=Visibilidad;
hInstApp:=0;
end;
{Ejecutamos}
{Execute}
ShellExecuteEx(pInfo);
{Esperamos que termine}
{Wait to finish}
repeat
exitCode := WaitForSingleObject(Info.hProcess,500);
Application.ProcessMessages;
until (exitCode <> WAIT_TIMEOUT);
end;
begin
RunAndWaitShell('c:\windows\notepad.exe','c:\autoexec.bat',Sw_ShowNormal);
end;
Si llamamos a un ejecutable, este se ejecutará.
Si llamamos a un fichero no ejecutable, la función ejecutará su aplicación asociada.
Por ejemplo, abrir un fichero HTML con el browser por defecto del sistema: