Tuesday, March 22, 2011

Inno Setup checkedonce flag in Code section

When using Inno Setup, you can set flags to any of the optional [Tasks] your installer might be preforming. We were using the 'checkedonce' flag for one of our tasks at work to make sure the Task was set by default only the first time we ran the installer on a machine. When we brought this Task into our [Code] section to be run by a custom Wizard page, we lost our checkedonce functionality.

The issue at hand is that we want to set the flag to be True if we are installing for the first time on a user's machine, and set to False if we are performing an upgrade. If we are preforming an upgrade on a machine, we should be able to find the Inno Setup app ID in the registry, stored here:
Software\Microsoft\Windows\CurrentVersion\Uninstall\{AppId}\
If we find this key, we know the installer has been run before, and we are preforming an upgrade. If we can't find it, it's a new install. Here's the code to check if it exists:

Note that we check both HKLM and HKCU, because [I think] the application install information could live in either one.

References
http://stackoverflow.com/questions/2000296/innosetup-how-to-automatically-uninstall-previous-installed-version

No comments:

Post a Comment