If I may suggest a "Experiment" ..
Try to see if inside the if, the "()" is interfering?
if exist arq (faz x) else (faz y)
... what I understand comes to explain the message: "All:(from", where the )
on the first command within the if
and in the following, both ()
...
Another point, seen in published reply in the ONLY, would use escape in the arguments ()
, as in:
icacls "myfolder\dummy" /deny *S-1-1-0:^(DE,WA^) *S-1-5-7:^(DE,WA^)
Experiment ..
Using the layout of the code below, I am replacing the execution within the if
by a goto
followed by a double loop
calling a call
...
@echo off & setlocal enabledelayedexpansion
set "LogFile=%appdata%\PermissaoArquivos.log"
set "Folders=Desktop,Documents,Pictures,Music,Videos
if not exist "!LogFile!" type nul >"!LogFile!" & goto :_apply_:
Rem Execute outros commandos, existe o arquivo: "!LogFile!"^^!
Rem Aqui entra seus outros commandos...
goto :eof
:_apply_:
echo Iniciando o processo em !DATE! !TIME! >>"!LogFile!"
for %%i in (%systemdrive%%homepath%\ %OneDriveCommercial%\ ) do (
for %%I in (!Folders!) do set "_Path_Folder=%%~i%%~I"
call :_deny_:
)
echo/Bloqueio de exclusao de diretorios do OneDrive aplicado em !DATE! as !TIME!>>"!LogFile!"
goto :eof
:_deny_:
icacls "!_Path_Folder!" /deny Todos:(de) >>"!LogFile!" && exit /b
echo/ error: "!_Path_Folder!" & timeout /t -1 & goto :eof
Experiment using Escape
@echo off & setlocal enabledelayedexpansion
set "LogFile=%appdata%\PermissaoArquivos.log"
set "Folders=Desktop,Documents,Pictures,Music,Videos
if not exist "!LogFile!" type nul >"!LogFile!" & goto :_apply_:
Rem Execute outros commandos, existe o arquivo: "!LogFile!"^^!
Rem Aqui entra seus outros commandos...
goto :eof
:_apply_:
echo Iniciando o processo em !DATE! !TIME! >>"!LogFile!"
for %%i in (%systemdrive%%homepath%\ %OneDriveCommercial%\ ) do (
for %%I in (!Folders!) do set "_Path_Folder=%%~I%%~I"& call :_deny_:
)
echo/Bloqueio de exclusao de diretorios do OneDrive aplicado em !DATE! as !TIME!>>"!LogFile!"
goto :eof
:_deny_:
icacls "!_Path_Folder!" /deny Todos:^(de^) >>"!LogFile!" && exit /b
echo/ error: "!_Path_Folder!" & timeout /t -1 & goto :eof
Your Code using Escape
@echo off & setlocal enabledelayedexpansion
set LogFile=%appdata%\PermissaoArquivos.log
if not exist %LogFile% (
echo Iniciando o processo em %DATE% %TIME% >> %LogFile%
icacls %systemdrive%%homepath%\Documents /deny Todos:^(de^) >> %LogFile%
icacls %systemdrive%%homepath%\Pictures /deny Todos:^(de^) >> %LogFile%
icacls %systemdrive%%homepath%\Music /deny Todos:^(de^) >> %LogFile%
icacls %systemdrive%%homepath%\Videos /deny Todos:^(de^) >> %LogFile%
icacls %systemdrive%%homepath%\Desktop /deny Todos:^(de^) >> %LogFile%
icacls "%OneDriveCommercial%\Desktop" /deny Todos:^(de^) >> %LogFile%
icacls "%OneDriveCommercial%\Documents" /deny Todos:^(de^) >> %LogFile%
icacls "%OneDriveCommercial%\Pictures" /deny Todos:^(de^) >> %LogFile%
icacls "%OneDriveCommercial%\Music" /deny Todos:^(de^) >> %LogFile%
icacls "%OneDriveCommercial%\Videos" /deny Todos:^(de^) >> %LogFile%
echo Bloqueio de exclusao de diretorios do OneDrive aplicado em %DATE% as %TIME% >> %LogFile%
)