Velocity Technical Archive
Batch file set permissions based on foldername %username%
Archived Reference: This is a historical technical article preserved from the Velocity Technologies knowledge base. For current Phoenix and East Valley managed IT services, explore our managed IT services or cybersecurity solutions.
@echo off\nset zLog=ResetHomePerms.log\ncls\necho FIXHOME.BAT\necho This script will reset permissions for all subdirectories\necho in this folder. It is assumed that the subdirectories\necho are named the same as their respective username.\necho.\nchoice /C YN /M "Are you sure you want to proceed?"\nif errorlevel 2 GOTO :Exit\nif errorlevel 1 GOTO :MAIN\n:MAIN\nif exist %zLog% del %zlog% >NUL\nchoice /C CF /M "Do you want users to have (C)hange or (F)ull control permissions?"\nif errorlevel 2 GOTO ResetF\nif errorlevel 1 GOTO ResetC\n:RESETF\necho Granting users FULL permissions\necho.\necho Granting users FULL permissions >>%zlog%\nfor /f %%i in ('dir /b /ad') do @echo %%i >>%zLog% && echo y|cacls %%i /T /g Administrators:F >NUL && cacls %%i /T /e /g %userdomain%%%i:F >>%zLog% && echo **********>>%Zlog%\nREM rem out or modify the following line if you do not want to give Domain Admins Full control\nfor /f %%i in ('dir /b /ad') do @echo %%i >>%zLog% && cacls %%i /T /e /g "%userdomain%Domain Admins":F >>%zLog% && echo **********>>%Zlog%\ngoto :CLOSE\n:RESETC\necho Granting users CHANGE permissions\necho.\necho Granting users CHANGE permissions >>%zlog%\nfor /f %%i in ('dir /b /ad') do @echo %%i >>%zLog% && echo y|cacls %%i /T /g Administrators:F >NUL && cacls %%i /T /e /g %userdomain%%%i:C >>%zLog% && echo **********>>%Zlog%\nREM rem out or modify the following line if you do not want to give Domain Admins Full control\nfor /f %%i in ('dir /b /ad') do @echo %%i >>%zLog% && cacls %%i /T /e /g "%userdomain%Domain Admins":F >>%zLog% && echo **********>>%Zlog%\ngoto :CLOSE\n:CLOSE\necho. >>%zLog%\ndate /t >>%zlog% && time /t >>%zLog%\necho.\necho See %zlog% for details\nset zLog=\nset zLogError=\n:EXIT\necho Exiting script