Windows – How to set file permissions for a whole disk using the command line in Windows 7

permissionswindows 7

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.

Best Answer

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.