How can I grant permissions to a user on a directory (Read, Write, Modify) using the Windows command line?
-
We are running the apache service as a specific user account, would this allow apache to access the document root with full rights? – Scott Fleming Aug 19 '21 at 20:21
20 Answers
As of Vista, cacls
is deprecated. Here's the first couple of help lines:
C:\>cacls
NOTE: Cacls is now deprecated, please use Icacls.
Displays or modifies access control lists (ACLs) of files
You should use icacls
instead. This is how you grant John full control over D:\test
folder and all its subfolders:
C:\>icacls "D:\test" /grant John:(OI)(CI)F /T
According do MS documentation:
F
= Full ControlCI
= Container Inherit - This flag indicates that subordinate containers will inherit this ACE.OI
= Object Inherit - This flag indicates that subordinate files will inherit the ACE./T
= Apply recursively to existing files and sub-folders. (OI
andCI
only apply to new files and sub-folders). Credit: comment by @AlexSpence.
For complete documentation, you may run "icacls
" with no arguments or see the Microsoft documentation here and here

- 6,634
- 4
- 38
- 90

- 5,937
- 1
- 18
- 13
-
-
4
-
24I had issues with access denied trying to change permissions in the windows explorer UI. Adding the /T flag to the end replaced existing objects and was able to solve the problem for me. C:>icacls "D:\test" /grant John:(OI)(CI)F /T – Alex Spence Jul 01 '14 at 03:56
-
12@AlexSpence Great point! The **/T** is needed to update the permissions of **existing files and folders**. The (OI) and (CI) only applies to files and folders created in the future. – Jesse Dec 11 '14 at 14:35
-
I wonder why I didn't need to add /T? Anyway thanks as this fixed my Win10 upgrade which seemed to have stripped the security of my user from the Documents folder (although ownership was intact) – Peter Nimmo Aug 09 '15 at 13:40
-
7Coming from the *nix world and being used to 'chown/chmod' to give access and set permissions via the CLI, this thread has been very helpful. – bgarlock Oct 27 '15 at 14:40
-
In Windows 10 I got this error: The term 'OI' is not recognized as the name of a cmdlet – Daniil Shevelev Dec 27 '15 at 14:25
-
1@DaniilShevelev If you're using PowerShell, then you probably need to quote the argument which has parentheses. Surrounding it in `'single quotes'` works. – jpaugh May 03 '16 at 15:31
-
@CălinDarie Your answer was tremendously helpful to me. Thanks! (I knew about `/T`, but not `(OI)(CI)`.) – jpaugh May 03 '16 at 15:33
-
1I get "OI : The term 'OI' is not recognized as the name of a cmdlet, function, script file, or operable program." with this command. edit: I was trying to run in Powershell, the command worked fine in CMD. – rleelr May 27 '16 at 09:38
-
Did anyone mention of a documentation bug of `icacls`? Specifically the `(D)` and `(DE)` rights as written in `icacls /?` have been wrong until corrected in Windows 7. `(DE)` is a simple right, while `(D)` is a group of rights that equals to `(DE,S)`. – Explorer09 Aug 13 '17 at 15:49
-
9If you run this in Powershell in Windows 10, you will get the error about "OI not recognized". Solution: Put the user+perms argument in quotes. For example: `C:\>icacls "D:\test" /grant "John:(OI)(CI)F" /T` – JDS Jan 08 '18 at 16:56
-
I get access denies when running this in an admin prompt, I had to run takeown /F C:\folder\*, good thing I only have 2 files in the root of that folder and not have subfolders. – user324747 Feb 05 '19 at 06:47
-
1This answer is actually really dangerous and misleading. Using this command without the /E parameter results in the files the permissions for the file being completely overwritten. The result of command above is that all permissions on the files are removed and replaced with granting John full access. – Mick Feb 13 '19 at 06:27
-
@Mick `cacls` is deprecated and this answer is using `icacls`, which doesn't even have a /E option. The command in this answer adds a permission for John and leaves existing permissions untouched. – camerondm9 May 15 '23 at 17:55
You can also use ICACLS.
To grant the Users group Full Control to a folder:
>icacls "C:\MyFolder" /grant Users:F
To grant Modify permission to IIS users for C:\MyFolder
(if you need your IIS has ability to R/W files into specific folder):
>icacls "C:\MyFolder" /grant IIS_IUSRS:M
If you do ICACLS /? you will be able to see all available options.

- 4,759
- 3
- 28
- 35
-
And given that `cacls` is gone, it's even *more* reason to use *icacls*. – Ian Boyd Nov 29 '12 at 20:52
-
5Adding full control didn't worked for me until `/grant Users:(OI)(CI)F` used – Jan Zahradník Sep 15 '14 at 10:52
-
Do I need to replace `Users` with something else or NO ? According to `icacls "C:\MyFolder" /grant Users:F` – iori Jan 13 '15 at 16:00
-
1If the current user is a member of the user group named "Users" (which, on Windows 7, is normally the case), then granting a permission to that group will affect the access rights of the current user. In any other case, replace the name Users with the actual name of the current user (e.g. John), thus: /grant John:(OI)(CI)F – Ed999 Nov 06 '18 at 05:49
Open a Command Prompt, then execute this command:
icacls "c:\somelocation\of\path" /q /c /t /grant Users:F
F
gives Full Access.
/q /c /t
applies the permissions to subfolders.
Note: Sometimes "Run as Administrator" will help.

- 12,978
- 3
- 74
- 76
-
3
-
Hi, I would like to set least permission for one user. For example, we have one application in Windows Server. So this user just need to access this application than any other services. Like user should not access any browser, should not access any file explorer, should not access any disk storage. This user should access just one stand-alone application. Is possible to do this case using windows command or any script in windows server? – Lakshminarayanan S Oct 14 '20 at 06:05
Use cacls
command. See information here.
CACLS files /e /p {USERNAME}:{PERMISSION}
Where,
/p : Set new permission
/e : Edit permission and kept old permission as it is i.e. edit ACL instead of replacing it.
{USERNAME} : Name of user
{PERMISSION} : Permission can be:
R - Read
W - Write
C - Change (write)
F - Full control
For example grant Rocky Full (F) control with following command (type at Windows command prompt):
C:> CACLS files /e /p rocky:f
Read complete help by typing following command:
C:> cacls /?

- 1
- 1

- 96,051
- 25
- 122
- 132
-
1Great answer! Only thing to note, is that files is the actual files you want to change the permissions on. Maybe [files] or {files} would be a better explanation. – Connor Ross Jan 30 '13 at 16:59
-
`cacls` is relevant; it is still available in `Windows 10`; Microsoft would deprecate `cmd.exe` in favour of Powershell too. – May 25 '17 at 14:47
-
1@Chinggis6 Being "still available" doesn't mean something is a good idea to use or recommend others to use. Also, `cmd.exe` is not deprecated and is not likely to be, so that's not a point in favour of `icacls` at all, quite the opposite. – underscore_d Jun 29 '17 at 15:05
-
1I know. I didn't state if it's a good idea to use or recommend `cacls.exe`. Neither did I mention that `cmd.exe` is already deprecated. I think people should at least be aware of its availability in higher versions even only for backward-compatibility or any other reason else. – Jun 29 '17 at 15:24
-
1Plus one for including the /e parameter to edit rather than replace the permissions on the files – Mick Feb 13 '19 at 06:47
I try the below way and it work for me:
- open
cmd.exe
takeown /R /F *.*
icacls * /T /grant [username]:(D)
So that the files can become my own access and it assign to "Delete" and then I can delete the files and folders.

- 13
- 4

- 241
- 2
- 2
-
1Do not run del *.* /S /Q. It will begin deleting all your files within your root directory. – James May 16 '21 at 12:17
-
takeown was the key for me when transferring files from windows 8.1 to 10 via external hdd – qwr Aug 27 '23 at 02:31
Corrupt Permissions: Regaining access to a folder and its sub-objects
Although most of the answers posted in reply to the question have some merit, IMHO none of them give a complete solution. The following (might be) a perfect solution for Windows 7 if you are locked-out of a folder by corrupted permission settings:
icacls "c:\folder" /remove:d /grant:r Everyone:(OI)(CI)F /T
For Windows 10 the user/SID must be specified after the /remove:d
option:
icacls "c:\folder" /remove:d Everyone /grant:r Everyone:(OI)(CI)F /T
.
Notes:
The command is applied to the specified directory.
Specifying the user "Everyone" sets the widest possible permission, as it includes every possible user.
The option "/remove:d" deletes any explicit DENY settings that may exist, as those override explicit ALLOW settings: a necessary preliminary to creating a new ALLOW setting. This is only a precaution, as there is often no DENY setting present, but better safe than sorry.
The option "/grant" creates a new ALLOW setting, an explicit permission that replaces (":r") any and all explicit ALLOW settings that may exist.
The "F" parameter (i.e. the permission created) makes this a grant of FULL control.
The "/T" parameter adds recursion, applying these changes to all current sub-objects in the specified directory (i.e. files and subfolders), as well as the folder itself.
The "(OI)" and "(CI)" parameters also add recursion, applying these changes to sub-objects created subsequently.
.
ADDENDUM (2019/02/10) -
The Windows 10 command line above was kindly suggested to me today, so here it is. I haven't got Windows 10 to test it, but please try it out if you have (and then will you please post a comment below).
The change only concerns removing the DENY setting as a first step. There might well not be any DENY setting present, so that option might make no difference. My understanding is, on Windows 7, that you don't need to specify a user after /remove:d but I might be wrong about that!
.
ADDENDUM (2019/11/21) -
User astark recommends replacing Everyone with the term *S-1-1-0 in order for the command to be language independent. I only have an English install of Windows, so I can't test this proposal, but it seems reasonable.

- 2,801
- 2
- 16
- 19
-
No provision is needed for INHERITED permissions, because EXPLICIT permissions override them. So, creation of the new explicit setting nullifies any inherited settings that may exist (because the new explicit setting includes recursion). – Ed999 Mar 19 '18 at 08:57
-
1
-
I am running (can only run) icacls.exe on Windows 7. I cannot comment on, nor test for, any changes to it which might exist on Windows 8 or 10. As tested by me on Windows 7 64-bit, the remove option is effective to remove DENY settings. Its use might result in an error message if there are NO deny settings present, but if there are none such then it can't remove them anyway. – Ed999 Nov 06 '18 at 04:57
-
Failure to reproduce _exactly_ the command line in my original answer (save for the directory path) will result in the command failing. In particular, do NOT add any quotation marks that do not feature in my answer. If you encase (for example) the /remove:d option in quotes, the command will of course fail. – Ed999 Nov 06 '18 at 05:27
-
yeah I did not use quotation marks. I'm using Windows 10 by the way. What's interesting is that /remove:d is a syntax parameter in the help output ```ICACLS name [/grant[:r] Sid:perm[...]] [/deny Sid:perm [...]] [/remove[:g|:d]] Sid[...]] [/T] [/C] [/L] [/Q] [/setintegritylevel Level:policy[...]]``` and heres additional information: ```/remove[:[g|d]] Sid removes all occurrences of Sid in the ACL. With :g, it removes all occurrences of granted rights to that Sid. With :d, it removes all occurrences of denied rights to that Sid.``` Any idea? – DFSFOT Nov 07 '18 at 11:32
-
1@DFSFOT Well, I sympathise. But I use Windows 7. With the grace of God, I will _never_ use Windows 10. I'd rather migrate to Ubuntu! I _suspect_ that /remove:g will probably remove all rights, both the ALLOW and the DENY entries (though with a possibility that 'granted' in this context means only ALLOW and so it will not process any DENY entries); whereas /remove:d will presumably _only_ remove the DENY entries, leaving any ALLOW entries unchanged. But of course I cannot be sure. – Ed999 Nov 12 '18 at 02:36
-
Perfect... however, you should replace `Everyone` by `*S-1-1-0` to be language independent. – astark Nov 08 '19 at 12:52
-
I struggled with this for a while and only combining the answers in this thread worked for me (on Windows 10):
1. Open cmd or PowerShell and go to the folder with files
2. takeown /R /F .
3. icacls * /T /grant dan:F
Good luck!

- 11,739
- 12
- 50
- 73
With an Excel vba script to provision and create accounts. I was needing to grant full rights permissions to the folder and subfolders that were created by the tool using our administrators 'x' account to our new user.
cacls looked something like this: cacls \FileServer\Users\Username /e /g Domain\Username:C
I needed to migrate this code to Windows 7 and beyond. My solution turned out to be:
icacls \FileServer\Users\Username /grant:r Domain\Username:(OI)(CI)F /t
/grant:r - Grants specified user access rights. Permissions replace previously granted explicit permissions. Without :r, permissions are added to any previously granted explicit permissions
(OI)(CI) - This folder, subfolders, and files.
F - Full Access
/t - Traverse all subfolders to match files/directories.
What this gave me was a folder on this server that the user could only see that folder and created subfolders, that they could read and write files. As well as create new folders.

- 41
- 4
Just in case there is anyone else that stumbles on this page, if you want to string various permissions together in the one command, I used this:
icacls "c:\TestFolder" /grant:r Test_User:(OI)(CI)(RC,RD,RX)
Note the csv string for the various permissions.

- 2,084
- 2
- 24
- 34
-
Thank you much. It helped me to set the permission for RX & RD. In most of the example given in the Internet was explained with /F full permission, Which should not be case. – Mani Aug 05 '15 at 14:46
XCACLS.VBS is a very powerful script that will change/edit ACL info. c:\windows\system32\cscript.exe xcacls.vbs help returns all switches and options.
You can get official distribution from Microsoft Support Page
-
3Can you provide a reference where `XCACLS.VBS` can be found? – Jeremy J Starcher Sep 20 '12 at 17:08
-
https://resources.oreilly.com/examples/9780735618688-files/blob/8b768deabe9200e0a5dd45bb20a1535892fc2687/9780735618688_files/Tools/Scripts/XCACLS%20VBS/XCACLS.vbs – Ed999 Oct 14 '20 at 15:02
Bulk folder creation and grant permission works me by using the below powershell script.
Import-Csv "D:\Scripts\foldernames.csv" | foreach-object {
$username = $_.foldername
# foldername is the header of csv file
$domain = “example.com”
$folder= "D:\Users"
$domainusername = $domain+“\”+$username
New-Item $folder\$username –Type Directory
Get-Acl $folder\$username
$acl = Get-Acl $folder\$username
$acl.SetAccessRuleProtection($True, $False)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("SYSTEM","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$domain\Domain Admins","Read", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($domainusername,"Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl $folder\$username $acl
}
Note: You have to create same domain username in csv file otherwise you will get permission issues

- 2,208
- 5
- 18
- 31

- 11
- 2
i was not able to open any file in a drive, this command unlocked all -
icacls i:\* /grant Users:F /t /q /c

- 5,440
- 13
- 53
- 83
-
Before issuing this command, you probably need to take over the ownership first using: `takeown /R /F "i:\*"`, then unlock with the above command, and then you can delete the directory using Windows Explorer. Don't forget also run the command as Administrator using command prompt. – Aryo May 02 '23 at 06:02
excellent point Călin Darie
I had a lot of scripts to use cacls I move them to icacls how ever I could not find a script to change the root mount volumes example: d:\datafolder. I finally crated the script below, which mounts the volume as a temporary drive then applies sec. then unmounts it. It is the only way I found that you can update the root mount security.
1 gets the folder mount GUID to a temp file then reads the GUID to mount the volume as a temp drive X: applies sec and logs the changes then unmounts the Volume only from the X: drive so the mounted folder is not altered or interrupted other then the applied sec.
here is sample of my script:
**mountvol "d:\%1" /L >tempDrive.temp && FOR /f "tokens=*" %%I IN (tempDrive.temp) DO mountvol X: %%I
D:\tools\security\icacls.exe %~2 /grant domain\group:(OI)(CI)F /T /C >>%~1LUNsec-%TDWEEK%-%TMONTH%-%TDAY%-%TYEAR%-%THOUR%-%TMINUTE%-%TAM%.txt
if exist x:\*.* mountvol X: /d**

- 4,325
- 9
- 40
- 59
I am Administrator and some script placed "Deny" permission on my name on all files and subfolders in a directory. Executing the icacls "D:\test" /grant John:(OI)(CI)F /T
command did not work, because it seemed it did not remove the "Deny" right from my name from this list.
The only thing that worked for me is resetting all permissions with the icacls "D:\test" /reset /T
command.

- 41
- 3
-
1It is possible to overcome the problem without using the reset command, by specifying ''/remove:d'' to delete any explicit DENY settings that may exist - see my perfect solution (above). – Ed999 Mar 19 '18 at 09:02
- navigate to top level directory you want to set permissions to with explorer
- type cmd in the address bar of your explorer window
- enter
icacls . /grant John:(OI)(CI)F /T
where John is the username - profit
Just adding this because it seemed supremely easy this way and others may profit - all credit goes to Călin Darie
.

- 2,079
- 18
- 39
When I ran the command:
icacls "c:/path/to/folderA/folderB" /grant:r Everyone:(OI)(CI)F /T
None of the files in folderB
were being processed, which was indicated via the output message:
Successfully processed 0 files; Failed processing 0 files
However, once I changed the specified path to the parent directory("c:/path/to/folderA"
) and re-ran the command all the files in folderB
were successfully processed.
Note: If you want any other files/folders in folderA
to not be processed, try moving all those files/folders to a different location before running the command above.
Hope this helps anyone running into the same issue.

- 1,817
- 3
- 14
- 25
For anyone needing to grant permissions to multiple drives, I created the following script:
@ECHO off
ECHO Run this with admin privileges
:: Change following variable to desired user or group
set UserOrGrp=Users
for %%d in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if EXIST %%d:\ (
ECHO Taking ownership of drive %%d:\
takeown /R /F %%d:\ /D Y /SKIPSL
ECHO Granting full control to %UserOrGrp%
icacls %%d:\* /Q /C /T /grant %UserOrGrp%:F
)
)

- 91
- 3
attrib +r +a +s +h <folder name> <file name> to hide
attrib -r -a -s -h <folder name> <file name> to unhide
-
2Those are attributes of the file (read-only, archive, system, hidden) not permissions, which are linked to user accounts. – Robin Bennett Jun 04 '13 at 16:06
in windows 10 working without "c:>" and ">"
For example:
F = Full Control
/e : Edit permission and kept old permission
/p : Set new permission
cacls "file or folder path" /e /p UserName:F
(also this fixes error 2502 and 2503)
cacls "C:\Windows\Temp" /e /p UserName:F

- 1
- 2
This is what worked for me:
Manually open the folder for which the access is denied.
Select the Executable/application file in that folder.
Right-click on it and go to Properties -> Compatibility
Now see the Privilege Level and check it for Run As Administrator
Click on Change Settings for all users.
The problem is solved now.
-
The question is for doing the above trough the command line. While your suggestion might work well, it is not applicable if you only have terminal access (ssh) to a sever which needs to be set up, thus you will need to use a cmd script – Ivaylo Slavov Dec 22 '14 at 13:21