Archive

Posts Tagged ‘uninstaller’

Mission Impossible: uninstalling everything

January 6, 2012 Leave a comment

The next release of zkanji is almost finished for some time now, but I couldn’t release it as I’m having lots of trouble writing an uninstaller program that does what it should, removing everything from the user’s computer. (Looking at the bright side, this means that the new functionality will be thoroughly tested and I’m also adding stuff I didn’t plan to add.) You wouldn’t believe how difficult it is to uninstall a program the right way, although if you are not so perfectionist, writing an uninstaller the not so right way is pretty straightforward.

The task of the uninstaller is nothing extraordinary. It has to:

  1. remove the program’s executable and other installed files,
  2. delete program icons from the start menu / desktop,
  3. remove install/uninstall information from the registry,
  4. remove user settings and user data files
  5. clean up the registry if anything is left there from user interaction (in this case it only means the auto start key if present).

1-3 is easy, everyone should be able to do it, as it was the installer that placed all those data on the computer in the first place. But the last two is not as easy as you would think. Let’s ignore the fact that I broke zkanji in the last version (will be fixed in the next release) and it can only be run from a folder not protected against the user (for example the Program Files is out of the question on Vista or 7 if you are not admin). If a program is installed to the Program Files and started by a simple user, it can only read the program folder, but can’t write anything to it. This means that the user generated data and settings files must be placed somewhere else (=stating the obvious). The Microsoft approved place for it is a folder called “Application data” (App data). This folder is separate for each user, so if you run the program from two separate accounts on the same computer, you can have different data and settings for them, and they won’t interfere with each other. Same thing applies to the registry. It can’t be modified freely by any user, so the only real possibility is to place everything to the current user’s registry branch.

This is all so good and nice, but not from an uninstaller’s point of view. It doesn’t automatically know where to look for extra junk. It could go check every user’s app data folder, removing the zkanji subfolder, and do the same with every user’s registry. Unfortunately this could result in nasty surprises for some users, who used their zkanji from a different install. For example if you placed the program in the program files for the average user but also have another version in a different folder, and you only wanted to remove one of them, you would end up deleting user data everywhere.

Another level of complication with zkanji is that there are several users (me included) who don’t want to use the registry, either because they think there is just enough junk in it already, or they want to use the program as a portable application, which shouldn’t leave anything on the computer at all, but write directly on the pen-drive or wherever it resides. Because of this I have to detect the situation when the program wasn’t installed. It is relatively simple, because the installer writes to the registry. There must be some uninstall information in there, so the system can list it in its “add or remove programs” list. Apart from that many setup programs also write to the registry key HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths. This is the best place to check, as it can hold the full path to your program. Unfortunately there can be link-to-folders and junction folders (that act like link-to-folders), and so the program can be on many separate virtual locations, even though they all represent the same physical data. I don’t want to write about the gory details of programming, but there are ways to check this situation, and identify different looking paths as being the same.

There is a solution to every problem, i.e. storing the path to the executable that created the user data at some central location for every single user and every executable. But it’s not enough to store this data, the uninstaller has to be able to work with it as well. And I haven’t even talked about running the program from remote computers. The task is complicated, even if it is not impossible, and after days of modifying the installer/uninstaller script, I’m starting to have enough. Maybe I should just make the uninstaller like it is for most other programs, ignoring data created for the user, even though it was the program that created it.

Update: I have decided not to remove user data when uninstalling the program. It only creates problems and in most cases it’s not what the user wants. So the next version of zkanji is now ready for release, but I’ll do a little more testing before I upload it.

Advertisements
Categories: Development, Rant Tags: