I'm using Inno Setup 5.5.6 (I can install a newer version if required) and I want to build a setup which deletes itself after it has been run.
My current approach (which doesn't work) is:
[Files]
Source: files\MyFile.dat DestDir: {app}; Flags: ignoreversion; \
AfterInstall: DeleteUpdateIfRequested;
and
function CmdLineParamExists(const Value: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to ParamCount do
if CompareText(ParamStr(I), Value) = 0 then
begin
Result := True;
Exit;
end;
end;
procedure DeleteUpdateIfRequested;
var
DeleteResult : Boolean;
begin
if CmdLineParamExists('/DELETESETUP') then
begin
MsgBox('Deleting file ' + ExpandConstant('{srcexe}'), mbInformation, MB_OK);
DeleteResult := DeleteFile(ExpandConstant('{srcexe}'));
if DeleteResult then
MsgBox('deleted', mbInformation, MB_OK)
else
MsgBox('not deleted', mbInformation, MB_OK);
end
else
MsgBox('Parameter nicht erkannt', mbInformation, MB_OK);
end;
The "Deleting..." message appears and the "not deleted..." one. It might be, that the setup.exe is still locked as it is still running. Is there maybe a later "step" where I could run the code?