0

I am looking for a command in cmd that will deny access to a certain folder to all users except for a specific one. I've tried with icacls but I couldn't do that.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Lee Wyi
  • 105
  • 7
  • Try with `cacls`: `for %A IN ("user1" "user2" "user3") do @cacls C:\testfolder /e /c /d %~A`. To allow access, add `:f` to the end. Please note that `user1`, `user2`, e.t.c are the users that won't have access to this folder. Is it working? – double-beep Feb 19 '19 at 12:59
  • Would you mind showing your attempt? – aschipfl Feb 19 '19 at 16:18
  • @double-beep, thanks for the reply but my goal is to block access to every user (I dont know the names of all of them) except one (myself).. Is there a way to block access to all existing users and to new ones in the future? – Lee Wyi Feb 20 '19 at 13:36
  • @LeeWyi perhaps `for /F "delims=" %%A IN ('dir /b C:\Users') do cacls C:\testfolder /e /c /d %%A 2>nul` – double-beep Feb 20 '19 at 13:43
  • @double-beep yes that's exactly what I needed! Thank you ! – Lee Wyi Feb 21 '19 at 10:06

1 Answers1

1

This is possible and can be done with the cacls command in :

for %A IN ("user1" "user2" "user3" "user4") do @cacls C:\some\folder /e /c /d %~A

where to allow access to these users to a certain folder again use:

for %A IN ("user1" "user2" "user3" "user4") do @cacls C:\some\folder /e /c /d %~A:f

Be sure to replace user1, user2, e.t.c. with the actual, correct usernames and add more if you want. You will need also to change C:\some\folder to the actual folder path.

For a solution, double the percent-signs like this:

@for %%A IN ("user1" "user2" "user3" "user4") do @cacls C:\some\folder /e /c /d %%~A:f
double-beep
  • 5,031
  • 17
  • 33
  • 41
  • Thanks for the reply. My main goal is to block access to everyone without knowing their names/logins and give access to only one specific user who has login=admin.. Is there a way to do this with icacls? – Lee Wyi Feb 20 '19 at 13:39