4

How can I change the permissions for a complete local disk (and all the files and folders within it) using the command prompt?

My username is XYZ and drive is local disk I.

2 Answers 2

4

Takeown

You can use takeown for this.

Enables an administrator to recover access to a file that previously was denied, by making the administrator the owner of the file.

Example:

takeown /r /d y /f * 

Where:

  • /r: Is a recursive operation on all files in the specified directory and subdirectories.
  • /d: Suppresses the confirmation prompt that is displayed when the current user does not have the List Folder permission on a specified directory.
  • /f: Specifies the file name or directory name pattern. You can use the wildcard character * when specifying the pattern.

Icacls

You can also use the icacls utility for this.

Displays or modifies discretionary access control lists (DACLs) on specified files, and applies stored DACLs to files in specified directories.

Example:

icacls "D:\path" /grant YOURUSER:(OI)(CI)F

Where:

  • 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.
0

In my case I also needed to cascade the permissions to all files using

icacls "D:\path" /reset /T /C

after using icalcs above

1
  • 1
    (1) Can you explain exactly what the /T and /C options do? (2) In what way was the command in the other answer inadequate?  What problem(s) did you have after using it?  … … … … … … … …  Please do not respond in comments; edit your answer to make it clearer and more complete. May 29, 2018 at 11:15

You must log in to answer this question.

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