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

4 Answers 4

12

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

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).

1

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

0

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

Y| works

Y | doesn't work

1
  • 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.
    – Community Bot
    Jul 14, 2022 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .