If you must access a file or a folder that you do not have rights to, you must first take ownership of that file or folder. When you do this, you replace the security permissions that were originally created for the file or folder.
To do this via Command Prompt you can use the “takeown” command.
A simple example would be:
takeown /f test.txt - which would take ownership of the file test.txt as the current user
In the example below – takeown /f * /r /d y – I have navigated into the parent folder TestFolder to take owner ship of all files and folders (including sub-directories) as the current user, and have specified that I would like to take ownership when prompted.

Takeown Command
You should get a message of success for each object this is carried out upon.
There are several useful arguments which can be used with the “takeown” command as demonstrated above.
/s <Computer> – Specifies the hostname or IP address of a remote computer (do not use backslashes). The default value is the local computer. This parameter applies to all of the files and folders specified in the command.
/u [<Domain>]<User name> – Runs the script with the permissions of the specified user account. The default value is system permissions.
/p [<Password>] – Specifies the password of the user account that is specified in the /u parameter.
/f <File name> – Specifies the file name or directory name pattern. You can use the wildcard character * when specifying the pattern. You can also use the syntax ShareNameFileName.
/a – Gives ownership to the Administrators group instead of the current user.
/r – Performs a recursive operation on all files in the specified directory and subdirectories.
/d {Y | N} – Suppresses the confirmation prompt that is displayed when the current user does not have the “List Folder” permission on a specified directory, and instead uses the specified default value.
Y: Take ownership of the directory.
N: Skip the directory.
Note that you must use this option in conjunction with the /r option.


