@echo off
setlocal EnableDelayedExpansion
REM Set NTFS permissions on share paths
set "shares_csv=%~dp0\shares-list.csv"
goto :main
:PromptUacAndFocus ScriptFullPath
setlocal
set "temp1="%TEMP%\%~nx0_1_%RANDOM%.vbs""
set "temp2="%TEMP%\%~nx0_2_%RANDOM%.vbs""
net sess>NUL 2>&1||goto 2>NUL||(
( echo CreateObject^("Shell.Application"^).ShellExecute "%~1",,,"RunAs",1) > %TEMP1%
(
echo strTmpFile_1 = %TEMP1%
echo strTmpFile_2 = %TEMP2%& echo.
echo Function CountWindowInstance^(strProcessName^)
echo CountWindowInstance = GetObject^("winmgmts:\\.\root\cimv2"^).ExecQuery^("Select * from Win32_Process Where Name = '" ^& strProcessName ^& "'"^).Count
echo End Function& echo.
echo Set WshShell = CreateObject^("WScript.Shell"^)& echo.
echo For I = 0 To 1
echo If CountWindowInstance^("consent.exe"^) ^> 1 Then WScript.Sleep 200 Else WScript.Sleep 50
echo WshShell.AppActivate^("User Account Control"^)
echo Next& echo.
echo On Error Resume Next& echo.
echo With CreateObject^("Scripting.FileSystemObject"^)
echo If .FileExists^(strTmpFile_1^) Then .DeleteFile^(strTmpFile_1^)
echo If .FileExists^(strTmpFile_2^) Then .DeleteFile^(strTmpFile_2^)
echo End With
) > %TEMP2%
for /l %%_ in (1,1,2) do ping >NUL
start WScript %TEMP1%
for /l %%_ in (1,1,2) do ping >NUL
start WScript %TEMP2%
for /l %%_ in (1,1,2) do ping >NUL
exit
)
endlocal
goto :eof
:main
call :PromptUacAndFocus %0
for /f "skip=1 delims=" %%I in ('type "%SHARES_CSV%"') do (
for /f "usebackq tokens=1,2,3 delims=," %%J in ('%%I') do (
set "locations=!LOCATIONS!,%%~K"
)
)
for %%I in (%LOCATIONS%) do (
set "location=%%~I"
icacls "!LOCATION:\=/!" /grant:r "Network:(OI)(CI)(F)" /c
)
REM remove the HomeUsers group from each %LOCATIONS%:
for %%I in (%LOCATIONS%) do (
set "location=%%~I"
icacls "!LOCATION:\=/!" /remove "HomeUsers" /c
)
echo.& echo Done.& echo.& echo Press any key to exit...& pause >NUL