views:

1408

answers:

8

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?

A: 

You could create a file in the program directory. The uninstaller won't remove this, since it wasn't added by the installer.

Jon B
+1  A: 

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

Gishu
This is not going to work properly for scenarios with multiple Windows users. If the file is per installation, the first run wizard will run only for the first user. If it's per-user, the install will overwrite it only for the user that does the install.
Franci Penov
Two different things - if it is an application-level setting, this idea would work.. store-and-look for it in a user-agnostic location like the program/install folder. If it is a user-level setting, store it in a user-specific location. Depends on what the req is...
Gishu
+2  A: 

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.

Guy Starbuck
Problem with the registry is if the setting goes in HKCU then it's a pain and non-standard to clear that out with the installer for users other than the current user. So if a different user runs the (un)install then you don't really have access to HKCU.
Rory
Unless you use a key or value within HKLM to maintain a list of the users that have run the wizard. I like that idea, but then you run into permission problems as many users can't write to HKLM. Which makes me think that @Franci's answer is the best.
Rory
A: 

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.

MusiGenesis
If this registry key is per-user, only the user that installed the app will get FRW. If that key is in HKLM, only admin users will be able to update it, thus any non-admin user will keep getting the FRW, until an admin runs the app.
Franci Penov
True. Plus, I think MS is not encouraging use of the registry anymore. Old habits die hard.
MusiGenesis
+2  A: 

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.

Franci Penov
A: 

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?

Pavel Chuchuva
How about because the program might introduce new important settings in the new version? :-)
Franci Penov
In this case your config file would miss those new important settings and based on that you would display configuration wizard on startup.
Pavel Chuchuva
Sure, that works as well. I just find that the FRW is a nice place to introduce the new functionality to the user, but after that it's up to her whether to use it or not.
Franci Penov
+1  A: 

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.

Dustin Townsend
Or do this but store in a value within HKLM, e.g. a multi-string value.
Rory
A: 

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.

Rory