Cacls commands and Applications

Source: Internet
Author: User

Cacls is a powerful command. Its main purpose is to quickly set user permissions for various folders and directories. No matter how many folders or complex file directories, you can use one command.

Before proceeding, remember:Do not use the following command for drive C and system folders !! We hereby warn you.Unless you are a NB-person!

By the way, if the screen prompts autochk program not found and skipping autocheck after the restart is found. And immediately go to the blue screen and prompt: stop: c unknown 21a unknown hard error. Congratulations! It's a great time to practice! It is useless not to search on the Internet. You do not have to reinstall the system. For the solution, see the next article!

The format of the Cacls command is as follows:

Display or modify the access control table (ACL) of a file)

Cacls filename [/T] [/E] [/C] [/G user: perm] [/R user [...]
[/P user: perm [...] [/D user [...]

Filename displays the ACL.
/T change the current directory and all its subdirectories
The ACL of the specified file.
/E. Edit the ACL without replacing it.
/C continues when an access denial error occurs.
/G user: perm grants the specified user access permission.
Perm can be: R read
W write
C Change (write)
F full control
/R user revokes the access permission of the specified user (only valid when used with/E ).
/P user: perm replaces the access permission of the specified user.
Perm can be: N none
R read
W write
C Change (write)
F full control
/D the user rejects access from the specified user.
You can use wildcards to specify multiple files in the command.
You can also specify multiple users in the command.

Abbreviation:
CI-container inheritance.
ACE will be inherited by the Directory.
OI-Object Inheritance.
ACE will be inherited by the file.
IO-only inherit.
ACE is not applicable to the current file/directory.

The following example shows how to use the Cacls command.

1. Use

C: \ Temp> Cacls % cd %/t/c/d samaria
Are you sure you want to (Y/N )? Y
Processed Directory: C: \ Temp
The file name, directory name, or volume label syntax is incorrect.

C: \ Temp> Cacls % cd %/t/c/g samaria: f
Are you sure you want to (Y/N )? Y
Processed Directory: C: \ Temp
Processed file: C: \ Temp \ text.txt
Processed Directory: C: \ Temp \ new folder

C: \ Temp>

Analysis:
The first command will deny the samaria user access to the c: \ temp directory, and the second command will re-grant the samaria user full control permissions. % Cd % indicates the current path. It can be used here. /. replace the current path with the command calcs. /. /t/c/d samaria, but both (% cd % and. /) The difference is that the former is a pure path, so the above two commands can be executed continuously,. /. no. The latter locates itself in the c: \ temp Directory during command execution, but the directory has been denied access, so an error occurs. /. the/t/c/g samaria: f command will get another result (or try again. (. /) Replace the current path! As follows:

C: \ Temp> Cacls././t/c/d samaria
Are you sure you want to (Y/N )? Y
Processed Directory: C: \ Temp
The file name, directory name, or volume label syntax is incorrect.

C: \ Temp> Cacls./t/c/g samaria: f
Are you sure you want to (Y/N )? Y
Processed Directory: C: \ Temp
Processed file: C: \ Temp \ text.txt
Processed Directory: C: \ Temp \ new folder

C: \ Temp>

2. Use it in batch files (the specific content of several bat files is as follows)

(1.bat) access to the file will be denied.

@ Echo Y | Cacls % */t/c/d samaria
@ Echo off

(2.bat) grant control permissions

@ Echo Y | Cacls % */t/c/p samaria: f
@ Echo off

(3.bat) set the current directory to "Access Denied"

@ Echo Y | Cacls././t/c/d samaria
@ Echo off

Analysis:
If you drag the required file to 1. bat or 2. bat, the file will be denied access (1.bat) or given control permissions (2.bat ). Y | Cacls indicates that the command is executed and the Y value is assigned to the Cacls command. % * is a parameter of the for command. Here, the for command is called by dragging, and * is a wildcard, when dragging, % * is equivalent to % 1. If it is changed to % 0, what will happen? For more extension parameters, refer to the instructions for the for command.
3. the bat file uses a relative path, so you do not need to drag the file when using it. Double-click 3.batand you can set the current directory (that is, 3. bat folder) is set to "Access Denied ". In this command, if you change the path to./or./, what is the difference? But do not replace the path symbol without understanding the meaning of the relative path. Otherwise, unexpected and serious consequences may occur!

Well, the usage of the Cacls command is basically completed above, and it will not be more complex. I have learned and played a few doscommands these days, and wrote Cacls in detail here, so that I can take notes and give some reference to anyone who needs them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.