I need to present a wizard once, the first time my windows forms application is run after install. I could use a user setting like firstrun = false I suppose. But I also need handle the case where the program is uninstalled, then reinstalled. How will that user setting be reset? It's already present in the config file in ...\Users--user--\AppData\Roaming... for that user. I need the wizard to run after any reinstalls so I need to reset that setting. Do I need to do this with a custom installer action?
You could create a file in the program directory. The uninstaller won't remove this, since it wasn't added by the installer.
Use a name-value pair like FirstRun=true in a settings file or a resx file. Read this file on startup, if true, show Wizard and set to false.
Each time you install, the copy of the file should be overwritten and hence you will get FirstRun=true. The wizard will run after every (re)install
The Windows registry seems like the appropriate place for this type of setting. An installer step could reset the key when the user reinstalls, or you could just clear out the registry key on uninstall if you don't want to keep any settings between installations.
It's probably best to have your installer create the FirstRun key in the registry and set it to true (or 1 or whatever), and make sure your uninstaller deletes this key entirely. Then just have your application read this key when it starts, and set it to false (or 0 or whatever).
If the user uninstalls and then reinstalls your application, they'll see the wizard again the first time they run it.
A per-user true/false setting will never work properly in the case of multiple Windows users using the same app. The installer is run only once as one of the Windows users and it will not have access to the per-user settings for all other users on that machine.
You could have a per-machine flag that would be set to true on install. However, if an admin user runs FRW and changes it, no other user will get FRW. If an non-admin user runs FRW, they won't be able to change it and will run FRW on next app run again.
What you need is a machine-wide timestamp of the isntallation and a per-user timestamp of when FRW was run. Here's the scenario:
On install, add a timestamp in the HKLM registry for your app. For each user, when the app is started check the timestamp of the first run wizzard (FRW) in the per-user settings file you mentioned above. If the per-user timestamp is older than the HKLM install stamp, run the FRW for that user and update the per-user settings file.
If the app is uninstalled and then installed again, the installer will update the HKLM timestamp, thus causing the FRW to be run for all users again.
I would suggest changing your program's behaviour and do not reset configuration settings after reinstall. After all, user already made his or her choice, why ask the same question again?
One could store a list of users that have already run the configuration wizard.
This list could be stored in a machine level configuration file or in the app directory. When the app is reinstalled this list could be cleared out.
Instead of looking at FirstRun, you would just check the current user with the list. If the user is in the list skip the configuration wizard. If the user is not in the list show the configuration wizard.
Similar to @Franci Penov's suggestion, I'd do it like this:
At install, create a registry value HKLM\Software\YourCompany\YourApp\InstallId using a newly generated GUID.
On first-run for a user, compare that value to HKCU\Software\YourCompany\YourApp\InstallId.
If the HKCU value doesn't exist or they're different, run your first-run logic and then copy HKLM\Software\YourCompany\YourApp\InstallId to HKCU\Software\YourCompany\YourApp\InstallId.
This has the (tiny) advantage of not being susceptible to time changes.