The problem is that [Run]
occurs after the Installation process successfully complete.
So you can't cancel at this point, you can only uninstall.
Also [Run]
does not allow you to get the exit code.
So you have a few options.
Use Event: procedure CurStepChanged(CurStep: TSetupStep);
And the call the {tmp}\test.bat
using Exec
or ExecAsOriginalUser
both of these return the ResultCode. You can then prompt the user to uninstall.
However I think that performing a cancel would be easier.
To do that, create an AfterInstall
Event on the last file in your project.
And execute the program from this event, as you can cancel from this event.
Here is some sample code that shows how it could be done.
[Files]
Source: "MYPROG.EXE"; DestDir: "{app}"; AfterInstall: MyAfterInstall
[Code]
procedure MyAfterInstall();
var
ResCode : Integer;
begin
if Exec(ExpandConstant('{tmp}') + '\test.bat',
'', SW_HIDE, ewWaitUntilTerminated, ResCode) then
begin
{ Program Ran successfully ResCode now contains exit code results }
{ if Exit was 10 then Cancel Installation. }
if ResCode = 10 then
begin
WizardForm.Close;
end;
end
else
begin
{ Problem running Program }
MsgBox('Error', SysErrorMessage(ResCode), mbError, MB_OK);
end;
end;