3

In my application, every user has its own settings, that I save to a subdirectory in that user's Application Data directory. During uninstall, I want to delete those settings for every user on the computer. How can I do that in Inno Setup?

In other words, I need to get a list that contains Application Data directory for each user (not the shared Application Data directory), so that I can delete the MyAwesomeApp directory from there. Is there some way to do that?

svick
  • 236,525
  • 50
  • 385
  • 514

2 Answers2

6

You can't, due to the design of Windows. The same design stops you accessing the profile folders too.

On top of this, it's accepted best practice to leave the user's data behind in case they want to reinstall it, roaming profiles, etc.

svick
  • 236,525
  • 50
  • 385
  • 514
Deanna
  • 23,876
  • 7
  • 71
  • 156
  • I remember the Windows Logo validation program allowing no single file created on install to remain after uninstall -- has this been changed? – springy76 Sep 18 '11 at 11:35
2

Assuming that your uninstaller runs with administrator priviledges, you can just get the User directory and then enumerate all the user directories there.

You can run an executable from Inno Setup written in whatever language you want. In it you can first get the current user's Application Data directory, using the SHGetSpecialFolderPath function. It would look something like this for Win7:

c:\Users\MyUser\AppData\Roaming\

You can use GetUserName to get the user's name (MyUser in this case), and find the parent directory and split the string to the parent directory "C:\Users\" and "AppData\Roaming\". You can then use FindFirstFile/FindNextFile to enumerate all users directories, and just append the second part "AppData\Roaming\" to them, and check if the file exists. By splitting the directory you get from SHGetSpecialFolderPath you ensure it would work both in XP (which would return something like C:\Documents and Settings\MyUser\Application Data") and in Win7. Basically you just replace MyUser with all the users' names in the string returned by SHGetSpecialFolderPath.

I have no idea if this avoids OS security or if it works with roaming users.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • 1
    Admin users may not necassarily have access to the user folders (yes, they can force their permissions on the folder and take it over though) and it won't effect roaming profiles. Note that if the user running the uninstall is using a roaming profile, you have just clobbered their settings for every other machine too. – Deanna Sep 16 '11 at 13:05
  • Also, local user folders might be encrypted - then there is no chance of accessing those. – jancha Sep 18 '11 at 11:22