How to Use CACLS.EXE in a Batch File

Article translations Article translations
Article ID: 135268 - View products that this article applies to.
This article was previously published under Q135268

NOTE: This article only applies to English language versions of Windows.

The CACLS.EXE command line utility does not provide a /Y switch that automatically answers with Y for Yes to the ARE YOU SURE? Y/N prompt. However, you can use the echo command to pipe the character Y as input to the ARE YOU SURE? Y/N prompt when you call Cacls.exe in a batch file.

To programmatically answer with Yes to the ARE YOU SURE? Y/N prompt during batch file execution, use the following command line in your batch file:
echo y| cacls filename /g username:permission
NOTE: Do not type a space between the "y" and the pipe symbol (|), otherwise, Cacls.exe fails to make the permission changes.

In larger batch files, this may produce the following error before continuing to the next line:
The Process tried to write to a nonexistent pipe.
The echo command does not expel its output before the system has a chance to build the pipe to cacls. There are different ways to work around this.

As an alternative, you can create a dummy file with just a "y" in it and use the syntax:
Cacls "F:\Directory" /g "Domain Users":R < yes.txt
Or you can use the xcacls utility which does allow the /y:
xcacls "F:\Directory" /e /g "Domain Users":R /y
For additional information about the syntax and usage of the Xcacls.exe utility, refer to the Xcacls.doc file included in the Windows NT Server 4.0 Resource Kit Supplement Three.
Expand all | Collapse all

Properties

Article ID: 135268 - Last Review: February 20, 2007 - Revision: 2.2
APPLIES TO
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional Edition
  • Microsoft Windows NT Server 3.5
  • Microsoft Windows NT Server 3.51
  • Microsoft Windows NT Server 4.0 Standard Edition
  • Microsoft Windows NT Workstation 3.5
  • Microsoft Windows NT Workstation 3.51
  • Microsoft Windows NT Workstation 4.0 Developer Edition
Keywords: 
KB135268

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com