JSI Tip 1254. How can I grant a user Full Control of an existing file?
Jerold Schulman
April 21, 1999
1 Min Read
In tip 0557, we granted a user Full Control of all new files and folders that they create in a directory.
To grant a user Full Control on existing files in a folder, use:
JSIFCU UserName FullFolderPath, where JSIFCU.bat contains:
@echo offif NOT {%2}
{} goto begin:syntax@echo Syntax: JSIFCU UserName Folder [/N]goto end:beginsetlocalset user=%1set folder=%2set folder=%folder:"=%if not exist "%folder%*.*" goto syntaxif /i {%3}
{/N} goto nokset found=Nfor /f "Tokens=*" %%i in ('net user %user%') do call :parse "%%i"if "%found%"
"N" goto syntax:nokfor /f "Tokens=*" %%i in ('dir /b /a-d /s "%folder%"') do call :doit "%%i"endlocalgoto end:doitCACLS %1 /E /C /P %user%:F goto end:parseset str=%1if %str%
"The command completed successfully." set found=Y:end
If you have a directory structure like:
FolderUserName1
FolderUserName2
FolderUserNameN
you can use JSIFCUAll.bat, which calls JSIFCU with the /N switch, to do them all.
JSIFCUAll.bat contains :
@echo offif NOT "%1"
"" goto begin:syntax@echo Syntax: JSIFCUAll TopFolder goto end:beginsetlocalset Folder=%1set folder=%folder:"=%if not exist "%folder%*.*" goto syntaxfor /f "Skip=4 Tokens=*" %%i in ('net users') do call :parse "%%i"endlocalgoto end:parseset str=#%1#set str=%str:#"=%set str=%str:"#=%if "%str%"
"The command completed successfully." goto endset substr=%str:~0,25%#set substr=%substr: =%set substr=%substr: #=%set substr=%substr:#=%if "%substr%"
"" goto endif exist "%folder%%substr%*.*" call JSIFCU "%substr%" "%folder%%substr%" /Nset substr=%str:~25,25%#set substr=%substr: =%set substr=%substr: #=%set substr=%substr:#=%if "%substr%"
"" goto endif exist "%folder%%substr%*.*" call JSIFCU "%substr%" "%folder%%substr%" /Nset substr=%str:~50,25%#set substr=%substr: =%set substr=%substr: #=%set substr=%substr:#=%if "%substr%"=="" goto endif exist "%folder%%substr%*.*" call JSIFCU "%substr%" "%folder%%substr%" /N:end
To grant a user Full Control of files that they own in a common folder, see tip 1255.
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like