Fixing messed up permissions on Vista

More than a year ago I was working at my thesis using the wireless TMote modules and TinyOS on Cygwin. Today, since the whole TinyOS SDK was still laying around on my hard disk, I decided to compress everything and to back it up, in order to free some space.

But it seems that, as it was installed, Cygwin completely messed up the folder's permissions: the only user with access was the very familiar sounding user "S-1-5-21-3632630550-1273522795-1072632642-1004" (WTF?). Neither the standard user nor the administrator had any permission on the whole folder.

In this case, the only thing you can do is to launch a command promt as administrator (the GUI permission interface doesn't work at all):

Admin command prompt, taking ownership of the folder.

Launch the following command:

takeown /F <folder> /R

This will assign ownership of the entire folder (and its subfolders) to the current user (the administrator). However, you still have no permissions:

icacls <folder> /grant:r <User>:(F) /T

The /grant:r part tells Icacls to grant permissions and to revoke (:r) all previously assigned permissions. This will clean up everything. The (F) part tells the utility to assign "Full" permissions to the specified user. Finally, the /T option extends all changes to all subfolder recursively.