12

I'm working on a custom settings script for Windows that will automate specific settings I want on a new Windows machine or installation. I grant access to some folders using cacls in my script, but I am prompted with the Y/N prompt for each listed item. I would like to bypass this by automatically saying "yes" for each folder or file I specify. I am aware of the risks with this and have had no issues thus far. Here is an example of one such directory in my script:

cacls "%PROGRAMFILES%\WindowsApps" /grant Administrators:f
Mr. Mendelli
  • 1,468

4 Answers4

13

I am prompted with the Y/N on each item

I would like to bypass this by automatically saying "yes" for each of these

You can pipe Y into cacls using echo:

echo Y| cacls "%PROGRAMFILES%\WindowsApps" /grant Administrators:f

The CACLS command does not provide a /Y switch to automatically answer 'Y' to the Y/N prompt. However, you can pipe the 'Y' character into the CACLS command using ECHO, use the following syntax:

ECHO Y| CACLS filename /g username:permission

Source Cacls - Modify Access Control List - Windows CMD - SS64.com

Removed space before pipe to fix command

bledd
  • 3
DavidPostill
  • 162,382
8

Use this syntax:

echo y| cacls.exe [options]...

Note that the command-line needs to be written exactly as above, including the blanks (see link).

harrymc
  • 498,455
1

Switch to icacls.exe (built into Windows), which doesn't have this prompt.

M. Niehaus
  • 11
  • 1
0

One quick note about the best answer, need to remove the space just before the pipe

Y| works

Y | doesn't work

bledd
  • 3