Description
This code allows to run any application regardless of its extension with more control
Delphi code
Function RunProcess(Const AppPath:String;
MustWait:Boolean=False;AppParams:String='';
Visibility:Word=SW_SHOWNORMAL):DWord;
Var
SI:TStartupInfo;
PI:TPROCessINFORMATION;
Proc:THandle;
zFileName:Array[0..Max_Path*2]of char;
zParams:Array[0..Max_Path]of char;
begin
FillChar(SI,SizeOf(SI),0);
SI.cb:=SizeOf(Si);
Si.wShowWindow:=Visibility;
If Not CreateProcess(strPCopy(zFilename,AppPath),
StrPCopy(zParams,APpParams),
nil,nil,False,NORMAL_PRIORITY_CLASs ,nil,nil,SI,PI) then
Raise EXCeption.CreateFmt('Failed to execute program '+
apppath+'.Error Code %d',[GetlastError]);
Proc:=PI.hProcess;
CloseHandle(Pi.HThread);
If MustWait then
If WaitForSingleObject(Proc,infinite)<>Wait_Failed then
GetExitCodeProcess(Proc,Result);
CloseHandle(Proc);
end;