Windows – batch script that grants admin rights and goes through all files and folders

batch fileicaclswindows

I have this, pretty sure its a little harsh but does the job, gives me all the rights to the files and folders on a drive when run on a drive, now I need help getting it to go into sub directories, so I dont need to copy the bat script inside every folder and have to run it.

takeown /f *
icacls * /grant Administrator:F
icacls * /grant Administrators:F
icacls * /grant SYSTEM:F
icacls * /grant "Authenticated Users":F

How would I get it to traverse the drive recursively?

Best Answer

Short Answer: add /t to (i)cacls

Long answer:

Here is my script I use when I want the file to be accessible to any user. It includes comments on what each flag does. Just put this in a batch file somewhere in the %AppData% folder.

REM --v2 -----------------------------------------------------------
takeown /r /d y /f %1
icacls %1 /t /grant Everyone:F

REM takeown /r /d y /f will set the owner to the Administrators group recursively.
REM /t makes it recursive
REM /grant Sets the permision to the following user, replaces existing permissions for the specified uesr.
REM :f Grants full controll permission.
REM ----------------------------------------------------------------

REM --v1 -----------------------------------------------------------
REM cacls %1 /t /e /g Everyone:f

REM /t makes it recursive
REM /e Edits the ACL instead of replaceing it
REM /g Grants permissions to the following users
REM :f Grants full controll permission.
REM ----------------------------------------------------------------

Then in %AppData%\Microsoft\Windows\SendTo create a shortcut to the batch script.

Edit the properties of that shortcut and go to Advanced... and check the box Run as Administrator.

enter image description here

Now in your right click menu -> Send To you will have a item called Fix Permissions any file or folder you do a Send To on will have the Everyone group given Full Access permissions. If you perform it on a folder it will recursively go through it and apply the permissions to all of the children in the folder.


I save the batch file the %AppData% folder because I am on a domain and that makes it part of my roaming profile so it will be on and ready to use on any computer I connect to.

Related Question