Archive: How to delete LOCALAPPDATA for all users


How to delete LOCALAPPDATA for all users
Hi everyone,

I'm trying to delete a whole directory inside $LOCALAPPDATA when I run the uninstaller for my app. The problem is that this only works for one user.

Since I request admin level to run the installer, just the admin's LOCALAPPDATA gets affected by this delete. Even if a standard user originally runs the installer, the elevation request then switches to the admin user. And that's why I only get to delete the admin's LOCALAPPDATA.

I noticed that using 'SetShellVarContext all' didn't work to make this delete universal (even though it helped me create/delete the shortcuts I created for all users).

So, would anybody know a way to delete LOCALAPPDATA for ALL users? Or at least for the standard user that originally runs the process before elevating to admin process?

Thanks in advance :)


LOCALAPPDATA is, as the name suggests, a local per-user directory. The all users directory is called APPDATA.

I can think of three ways to solve your problem.
1) Use EnumUsersReg and try to get the directory location from registry. There is a very large chance that this will NOT work properly on all machines out there.
2) Use the UAC plugin to delete the local directory directly, from user level. This will definitely work, but only for the one user starting the installer, not for any other users that might exist on the machine. Also, this should take a bit more time to implement correctly.
3) Create a textfile in $instdir, use the accesscontrol plugin to enable write privileges for all users on that file, and have your software save the location of LocalAppData to that file. Read the file during uninstallation, so you'll know which directory to delete.


Run your (un)installer without admin rights ? (RequestExecutionLevel)