Custom uninstall code when uninstalling a specific component

363 views
Skip to first unread message

Sebastian P.R. Gingter

unread,
Apr 27, 2021, 12:15:30 PM4/27/21
to innosetup
Hi,

I have a component that installs a 3rd party dependency via executing a bundled installer from the {tmp} folder. This dependency is a device driver.
I install it by having the setup.exe of this driver in my files:
Source: "..\artifacts\USBDriver\*"; DestDir: "{tmp}\UsbDriver"; Flags: ignoreversion deleteafterinstall; Components: USBDriver; AfterInstall: InstallUSBDriver
In the afterinstall script I execute the setup.exe with silent flags.

This separate installer also creates a separate uninstaller for the driver.
So, when uninstalling this component, I need to execute this "uninstall.exe" which is located in the "%ProgramFiles%\DriverVendor\DriverName\" folder after installation.

However, I seem to miss a possibility to provide a script for OnUninstall or Before/After Uninstall for that component (or file, for that matter).

I thought about using the CurUninstallStepChanged procedure for that, but I need to know if that component or 3rd party driver was really installed by my setup, or if someone else installed that driver (then I should not remove it).

So, is there a way I can't find to execute custom uninstall code per installed component, or how can I find out if a specific component needs to be uninstalled in the CurUninstallStepChanged method?

Thanks,

   Sebastian  

Gavin Lambert

unread,
Apr 27, 2021, 6:05:10 PM4/27/21
to inno...@googlegroups.com
On 28/04/2021 4:15 am, Sebastian P.R. Gingter wrote:
> However, I seem to miss a possibility to provide a script for
> OnUninstall or Before/After Uninstall for that component (or file, for
> that matter).
>
> I thought about using the CurUninstallStepChanged procedure for that,
> but I need to know if that component or 3rd party driver was really
> installed by my setup, or if someone else installed that driver (then I
> should not remove it).
>
> So, is there a way I can't find to execute custom uninstall code per
> installed component, or how can I find out if a specific component needs
> to be uninstalled in the CurUninstallStepChanged method?

If you use [UninstallRun] (don't forget the RunOnceId!) then it will be
run if the component was ever installed. It just works.

Using CurUninstallStepChanged gives you a bit more control over the
process (in particular, the ability to interpret exit codes), but you're
a bit more on your own.

You can use IsComponentSelected to see if the component was selected in
the most recent install/upgrade (which will usually be the case when the
component is installed), but it is possible to trick it if they unticked
the component at some point (and hence failed to upgrade it). Otherwise
you'd have to check if a file or registry key unique to that component
is installed or not.

Gavin Lambert

unread,
Apr 27, 2021, 6:09:46 PM4/27/21
to inno...@googlegroups.com

Mere moments ago, quoth I:
> Otherwise you'd have to check if a file or registry key unique to
> that component is installed or not.
If it's an EXE-based uninstaller (and not an MSI), then a pretty safe
bet would be to check if the uninstaller itself still exists.

Sebastian P.R. Gingter

unread,
Apr 28, 2021, 6:08:34 AM4/28/21
to innosetup
Thanks, Gavin.

That helped a lot. I can now install and uninstall the driver perfectly.

Cheers,

   Sebastian

Reply all
Reply to author
Forward
0 new messages