This script changes the owner of each folder within Redirected Folders to the administrators group. Then it grants full control to administrators and the user the folder is named after. It then changes the owner back to that user. It only works if your usernames are exactly the same as your folder names. Also it does not work for usernames with spaces in them.
By making the user the owner of the folder it keeps folder redirection working properly.
REM This script does not work when folders have spaces in them.
REM This script must be run as an admin in an elevated command line.
REM This script changes the owner of each folder within Redirected Folders to the administrators group. Then it grants full control to administrators and the user the folder is named after. It then changes the owner to that user.
SETLOCAL
SET “sourcedir=C:\Redirected Folders”
PUSHD %sourcedir%
FOR /f “tokens=1*” %%a IN (
‘dir /b /a:d’
) DO (
takeown /F %%a /R /D Y
icacls %%a /grant %%a:^(OI^)^(CI^)F /T
icacls %%a /grant administrators:^(OI^)^(CI^)F /T
icacls %%a /setowner %%a /T
)
POPD
GOTO :EOF
Recent Comments