Unable to delete folder – “You need permission to perform…”

Tip to solve “You need permission to perform this action” problem on Windows 7.

Create a small batch (.bat) command on your system, as follows:

takeown /f %1 /r /d y
icacls %1 /grant administrators:F /t

From an command prompt, you can run the command such as yourCommandCreated d:\unable_to_delete and this will reset ownership and ACLs on the unable_to_delete directory such that a command like rd /s d:\unable_to_delete should work.