Friday, January 3, 2014

How to grant permission to users for a directory using command line in Windows?

Ref: http://stackoverflow.com/questions/2928738/how-to-grant-permission-to-users-for-a-directory-using-command-line-in-windows

Use ICACLS command
  • 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
  • According do MS documentation:
F= Full Control
CI= 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.
For complete documentation, you may run "icacls" with no arguments or see the Microsoft documentation here and here
  • 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.
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 /?
เพิ่มเติม
attrib +r +a +s +h <folder name> <file name> to hide
attrib -r -a -s -h <folder name> <file name> to unhide

No comments:

Post a Comment

Popular Posts