I try to execute an .exe in the CurStepChanged
procedure at (CurrentStep = ssPostInstall)
, the .exe is part of the [Files]
section. It seems to me as if the ssPostInstall
is executed multiple times – sometimes even before the files of the installation process are processed. Of course I could extract the .exe to a temporary folder but as I would like to understand the behavior it’s disappointing. The moment when the ssPostinstall
step is reached seems to vary every time I execute and sometimes is reached more than one time. Am I missing something? Here is a part of my code:
procedure CurStepChanged(CurrentStep: TSetupStep);
var ErrorCode : Integer;
begin
if (CurrentStep = ssPostInstall) then begin
if Exec(ExpandConstant('{app}\{code:getVersionSubdir}\licencing\haspdinst.exe'), '-i', '',SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
begin
if ErrorCode = 0 then else
MsgBox(SysErrorMessage(ErrorCode), mbCriticalError, MB_OK);
end;
end
else begin
MsgBox('Did not work', mbCriticalError, MB_OK);
end;
end;
Thanks in advance
Chris
The nesting and indentation in your code makes the issue non obvious, but hen the code is indented correctly, it becomes a lot more obvious that the nesting of your messages is wrong.
procedure CurStepChanged(CurrentStep: TSetupStep);
var ErrorCode : Integer;
begin
if (CurrentStep = ssPostInstall) then
begin
if Exec(ExpandConstant('{app}\{code:getVersionSubdir}\licencing\haspdinst.exe'), '-i', '',SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
begin
if ErrorCode = 0 then
else
MsgBox(SysErrorMessage(ErrorCode), mbCriticalError, MB_OK);
end;
end
else
begin
MsgBox('Too early? Did not work', mbCriticalError, MB_OK);
end;
end;
Note the lack of begin
/end
in the ErrorCode
if
blocks meaning a single statement is conditional. The "did not work" message is in the else
block of the if (CurrentStep=ssPostInstall) then
.
How about something like this (air code):
procedure CurStepChanged(CurrentStep: TSetupStep);
var ErrorCode : Integer;
begin
if (CurrentStep = ssPostInstall) then
begin
if not Exec(ExpandConstant('{app}\{code:getVersionSubdir}\licencing\haspdinst.exe'), '-i', '',SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
begin
// Exec returned failure
MsgBox('Did not work', mbCriticalError, MB_OK);
end;
else if ErrorCode <> 0 then
begin
// Exec returned success but non 0 error code
MsgBox(SysErrorMessage(ErrorCode), mbCriticalError, MB_OK);
end;
// Else here if you want to do something on success
end;
end;
The importance of tidy code :p
(And why I never miss out {
/}
and begin
/end
in blocks, even when not needed)