Reputation: 43
I want to make a batch file which applies permissions to a given user folder using icacls. This is the batch file i made :
@echo off set /p username=Enter username: echo Select permissions : echo N - no access echo F - full access echo M - modify access echo RX - read and exe echo R - read-only acc echo W - write-only ac echo D - delete access echo. set /p perm=Enter permissions: if %perm%==F icacls "C:\Users\%username%" /grant:r "%username%:(OI)(CI)F"
When i run this file and enter permissions as F, it displays this error : The syntax of the command is incorrect. but if i run the same command directly in cmd it works perfectly. So, how do i correct the command in batch file so that it runs without any issues?
Upvotes: 4
Views: 17158
Reputation: 31231
It looks like the syntax of your if
command is causing the problems. You are checking if the permission chosen is F
but then not doing anything with it.
Try either putting it on one line
if %perm%==F icacls "C:\Users\%username%" /grant:r "%username%:(OI)(CI)F"
or in brackets
if %perm%==F (
icacls "C:\Users\%username%" /grant:r "%username%:(OI)(CI)F"
)
Upvotes: 3