Archive: Deleting "Application Data" from Multiple Users during Uninstall?


Deleting "Application Data" from Multiple Users during Uninstall?
The program I am installing creates a folder in each individual user's "application data" directory when the user runs the app. I'm wondering if there is a way to find every "application data" folder that the app created and remove it when I run the NSIS uninstaller (running with admin priviledges, of course.)

As an addendum to that question, does anyone know if you could do a partial uninstall - only remove shortcuts and application data for each individual user rather than everyone. Then, when the last person to have the program uinstalls it, remove everything?


Either create a list (INI file or registry) of all application data dirs created on install, and read the list (ReadINI/RegString) on uninstall.
Another option is to create a unique file in any application data dirs created by the installer (with FileOpen, FileWrite, FileClose) and delete those dirs that contain the unique file on uninstall (check if the file exists with IfFileExists).

-Stu


You can also get every folder with EnumUsersReg and HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders. Actually, EnumUsersReg even shows you how to get the profile directories list (SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList).


I've come up with a first attempt at a solution (haven't tried kichik's method, but I'll check it out, thanks!) Sorry if this problem/solution seems a bit ameteur, I just started NSIS yesterday:


FindFirst $0 $1 "c:\documents and settings\*"
loop:
StrCmp $1 "" done
StrCmp $1 "." continue
StrCmp $1 ".." continue

RMDir /r /REBOOTOK "c:\documents and settings\$1\Application Data\my_program"

continue:
FindNext $0 $1
Goto loop
done:


I hope to have a per-user uninstall option setup next. Thanks again.

kichik's method worked great except for one small catch:



Section "un.install"
...
${EnumUsersReg} un.EraseAppDataCB temp.key
...

SectionEnd

Function "un.EraseAppDataCB"
Pop $0
ReadRegStr $0 HKU "$0\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "AppData"
RMDir /r /REBOOTOK "$0\my_program"
FunctionEnd


You have to edit EnumUsersReg in order to enable it to work during the uninstallation proceess (as opposed to during the install process.) Simply add "un." in front of "_EnumUsersReg" on lines 73 and 82. A better solution would probably be to create a second version of the macro specifically for uninstall purposes.

MankyD,
Your first solution of sweeping through the "C:\Documents and settings" folder won't always work. The PC may not have a "C" drive, or the person setting up the users may have chosen a differnt location for each user's home appdata directory.

The EnumUsersReg suggestion is a more fool-proof solution.