Taking Ownership of a File Using the Command Line

Feedback

This command is commonly employed on batch files to allow an administrator to regain access to a previously denied file by assuming ownership of it.

Syntax

takeown [/s  [/u [] [/p []]]] /f  [/a] [/r [/d {Y|N}]]
Parameters
Parameter Description
/s

<computer>
The parameter specifies the hostname or IP address of a remote computer (without using backslashes). By default, the local computer is used. This parameter is applicable to all the files and folders mentioned in the command.
/u

[<domain>]<username>
The script is executed using the permissions of the designated user account, with the default being system permissions.
/p

[<[password>]
Specifies the password for the user account mentioned in the /u parameter.
/f

<filename>
The pattern for the file name or directory name can be specified using the wildcard character

*

. Additionally, the syntax

<sharename><filename>

can also be used.
/a The option of assigning ownership to the Administrators group is available instead of assigning it to the current user. If this option is not specified, the ownership of the file will be given to the user currently logged on to the computer.
/r Executes a recursive action on every file within the designated directory and its subdirectories.
/d

{Y | N}
The confirmation prompt that appears when the current user lacks the List Folder permission for a specified directory can be suppressed. Instead, a default value can be used. The valid options for the /d parameter are:
– Y: Acquire ownership of the directory.
– N: Skip the directory.


NOTE


You must use this option in conjunction with the

/r

option.

/? Provides assistance through the command prompt interface.
“””.

Remarks

  • The command takeown does not support mixed patterns using “?” and “*”.

  • After utilizing the “takeown” command to remove the lock, it may be necessary to utilize Windows Explorer in order to grant yourself complete permissions to the files and directories, enabling their deletion.

Examples

To execute the command for retrieving the file named “Lostfile” with the identifier
ownership of a file
, enter the following line of code:

takeown /f lostfile

Additional References

  • Command-line syntax key

Frequently Asked Questions

Posted in Uncategorized