How to Take Ownership of a File, Folder Using Command-line in Window 7 and Vista

Taking ownership of a file

Click Start, click All Programs, click Accessories, right-clickCommand Prompt, and then click Run as Administrator.
Type the following command and press ENTER:  TAKEOWN /F<filename>
(Replace the text <filename> with the full path of the actual file.)
If the operation was successful, you should see the following message:
“SUCCESS: The file (or folder): “filename” now owned by user “Computer Name\User name“.”
Then to assign the Administrators group Full Control Permissions for the file, you may use the ICACLS command.
Use this syntax:  ICACLS <filename> /grant administrators:F

Taking ownership of a folder

Use the following syntax:  takeown /f <foldername> /r /d y
Then to assign the Administrators group Full Control Permissions for the folder,
use this syntax: icacls <foldername> /grant administrators:F /T
The /T parameter is added so that the operation is carried out through all the sub-directories and files within that folder.
Command-line help:
To know more information about the above commands, run these commands from a Command Prompt window.
takeown /?

icacls /?

No comments:

Post a Comment