copy the STO_ShellExecute to your project see Interpretation for an exemple how to use it with params
uses
Windows, ......., ShellApi;
function TFormBegin.Interpretation():Boolean;
var ExitCode: DWORD;
rf:TextFile;
i:integer;
msg:string;
reponse:Boolean;
prog,args:String;
begin
reponse := TRUE;
DeleteFile(ReponseFile);
i := 1;
while (i<=StrLen(PChar(BatFile))) and (BatFile<>' ') do begin
prog := prog + BatFile;
inc(i);
end;
while (i<=StrLen(PChar(BatFile))) do begin
args := args + BatFile;
inc(i);
end;
//execution du fichier "BAT"
STO_ShellExecute(prog,args,200000,False,ExitCode);
//traitement du reponse
AssignFile(rf,ReponseFile);
{$I-}
Reset(rf);
{$I+}
if IOResult<>0 then begin
showmessage('Fichier '+ReponseFile+' non trouvé');
reponse := FALSE;
end
else begin
readln(rf,i);
readln(rf,msg);
if i>0 then begin
ShowMessage(msg);
reponse := FALSE;
end
else for i:=1 to Nb_exec do
ShellExecute(0,'open',PChar(ExecFile),'','',SW_NORMAL);
CloseFile(rf);
end;
if reponse then Timer1.Enabled := TRUE;
Interpretation := reponse;
end;
////////////////////////////////////////////////////////////////
// AppName: name (including path) of the application
// AppArgs: command line arguments
// Wait: 0 = don't wait on application
// >0 = wait until application has finished (maximum in milliseconds)
// <0 = wait until application has started (maximum in milliseconds)
// Hide: True = application runs invisible in the background
// ExitCode: exitcode of the application (only avaiable if Wait <> 0)
//
function STO_ShellExecute(const AppName, AppArgs: String; const Wait: Integer;
const Hide: Boolean; var ExitCode: DWORD): Boolean;
var
myStartupInfo: TStartupInfo;
myProcessInfo: TProcessInformation;
sAppName: String;
iWaitRes: Integer;
begin
// initialize the startupinfo
FillChar(myStartupInfo, SizeOf(TStartupInfo), 0);
myStartupInfo.cb := Sizeof(TStartupInfo);
myStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
if Hide then // hide application
myStartupInfo.wShowWindow := SW_HIDE
else // show application
myStartupInfo.wShowWindow := SW_SHOWNORMAL;
// prepare applicationname
sAppName := AppName;
if (Length(sAppName) > 0) and (sAppName[1] <> '"') then
sAppName := '"' + sAppName + '"';
// start process
ExitCode := 0;
Result := CreateProcess(nil, PChar(sAppName + ' ' + AppArgs), nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, PChar(ExtractFilePath(AppName)),
myStartupInfo, myProcessInfo);
// could process be started ?
if Result then
begin
// wait on process ?
if (Wait <> 0) then
begin
if (Wait > 0) then // wait until process terminates
iWaitRes := WaitForSingleObject(myProcessInfo.hProcess, Wait)
else // wait until process has been started
iWaitRes := WaitForInputIdle(myProcessInfo.hProcess, Abs(Wait));
// timeout reached ?
if iWaitRes = WAIT_TIMEOUT then
begin
Result := False;
TerminateProcess(myProcessInfo.hProcess, 1);
end;
// get exitcode
GetExitCodeProcess(myProcessInfo.hProcess, ExitCode);
end;
CloseHandle(myProcessInfo.hProcess);
end;
end;