10

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,239
  • 2
  • 24
  • 42

4 Answers4

11

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
  • 2
DavidPostill
  • 153,128
  • 77
  • 353
  • 394
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
  • 455,459
  • 31
  • 526
  • 924
1

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

Stephen Rauch
  • 3,091
  • 10
  • 23
  • 26
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
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 14 '22 at 13:16