I need to delete some files after the installation finishes.
I was using the [RUN] section to call CMD to delete the files but I wanted to improve the deletions by using InnoSetup code and not Batch then I've seen the [InstallDelete] section but this delete the files BEFORE the [RUN] section so... there is something I can do to delete the files after [RUN] section?
Here is my script:
#define InstallerName "VirtualBox-4.2.16-r86992-MultiArch_amd64.msi"
#define ExtensionName "Oracle_VM_VirtualBox_Extension_Pack-4.2.16-86992.vbox-extpack"
[Setup]
AppName=VirtualBox
blah blah blah...
blah blah blah...
[Files]
Source: {tmp}\*; DestDir: {tmp}; Flags: deleteafterinstall recursesubdirs createallsubdirs ignoreversion
[Run]
Filename: {tmp}\{#InstallerName}; Parameters: "/passive /norestart ADDLOCAL=VBoxApplication INSTALLDIR=""{app}"""; StatusMsg: Instalando VirtualBox...; Flags: shellexec RunHidden WaitUntilTerminated
Filename: {tmp}\xml.exe; Parameters: "ed --inplace -N N=""http://www.innotek.de/VirtualBox-settings"" --update ""//N:ExtraDataItem[@name='GUI/UpdateDate']/@value"" --value never ""{%userprofile}\.virtualbox\virtualbox.xml"""; StatusMsg: Instalando VirtualBox...; Flags: RunHidden WaitUntilTerminated
Filename: {app}\VBoxManage.exe; Parameters: "extpack install --replace ""{tmp}\{#ExtensionName}"""; StatusMsg: Instalando Extension Pack...; Flags: RunHidden WaitUntilTerminated
Filename: {app}\virtualbox.exe; Description: {cm:LaunchProgram,VirtualBox}; Flags: shellexec postinstall unchecked skipifsilent nowait
[InstallDelete]
Name: {commondesktop}\Oracle VM VirtualBox.lnk; Type: files
Name: {commonstartmenu}\Programs\Oracle VM VirtualBox; Type: filesandordirs
If you're trying to delete temporary files (eg. needed by a subinstall):
Anything you install to {tmp}
will automatically be deleted at the end of the install.
If you cant' install to {tmp}
for some reason then you can use the deleteafterinstall
flag on the [Files]
entry.
If you're trying to delete files created by that subinstall, then you should contact the vendors or check their documentation and see if there's a command line parameter you can pass to suppress installation of that item in the first place. There usually should be for optional things like desktop icons.
You can delete your files in the post install step of the CurStepChanged
event handler
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then begin
DeleteFile(ExpandConstant('{commondesktop}\Oracle VM VirtualBox.lnk'));
..
Finally what I've did is this.
Firts I try to delete the original MSI package files if them exists in the [InstallDelete] section but that doesnt's delete the folder at all so then after that I extract a dummy file and folder in the same locations with the "deleteafterinstall" flag to delete them.
If you think this can be improved then please just tell me how to do it, really I don't want to use external code for this because I need a "generic" way to do it for about 200 installers, writting code for that quantity of installers take a lot of time.
#define InstallerName "VirtualBox-4.2.16-r86992-MultiArch_amd64.msi"
#define ExtensionName "Oracle_VM_VirtualBox_Extension_Pack-4.2.16-86992.vbox-extpack"
[Setup]
AppName=VirtualBox
...
...
[InstallDelete]
Name: {commondesktop}\Oracle VM VirtualBox.lnk; Type: files
Name: {commonstartmenu}\Programs\Oracle VM VirtualBox; Type: filesandordirs
[Dirs]
Name: {commonstartmenu}\Programs\Oracle VM VirtualBox; Flags: deleteafterinstall; attribs: hidden
[Files]
Source: {commondesktop}\Oracle VM VirtualBox.lnk; DestDir: {commondesktop}; Flags: deleteafterinstall ignoreversion; Attribs: hidden
Source: {tmp}\*; DestDir: {tmp}; Flags: deleteafterinstall recursesubdirs createallsubdirs ignoreversion
[Icons]
Name: {userstartmenu}\Programs\Multimedia\VirtualBox; Filename: {app}\virtualbox.exe; WorkingDir: {app}
[Run]
Filename: {tmp}\{#InstallerName}; Parameters: "/passive /norestart ADDLOCAL=VBoxApplication INSTALLDIR=""{app}"""; StatusMsg: Instalando VirtualBox...; Flags: shellexec RunHidden WaitUntilTerminated
Filename: {tmp}\xml.exe; Parameters: "ed --inplace -N N=""http://www.innotek.de/VirtualBox-settings"" --update ""//N:ExtraDataItem[@name='GUI/UpdateDate']/@value"" --value never ""{%userprofile}\.virtualbox\virtualbox.xml"""; StatusMsg: Instalando VirtualBox...; Flags: RunHidden WaitUntilTerminated
Filename: {app}\VBoxManage.exe; Parameters: "extpack install --replace ""{tmp}\{#ExtensionName}"""; StatusMsg: Instalando Extension Pack...; Flags: RunHidden WaitUntilTerminated
Filename: {app}\virtualbox.exe; Description: {cm:LaunchProgram,VirtualBox}; Flags: shellexec postinstall unchecked skipifsilent nowait
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With