Q: How can I take ownership of a file or folder from the command line?
A: In Windows Vista, Microsoft introduced the Takeown.exe command-line tool, which can be used to take ownership of a file or folder. You need to run this tool from an elevated command prompt window. (Click Start, open the Accessories folder, right-click Command Prompt, and click Run as administrator.)
To take ownership of a file, run the command:
In this command, you must replace <filename> with the full file system path to the file you want to take ownership of. If the command is successful, you'll see a message similar to the following: SUCCESS: The file (or folder): "filename" now owned by user "Computer Name\User name".
To take ownership of a folder, use the command:
In this command, you must replace <foldername> with the full file system path to the folder you want to take ownership of. You need to include the /r switch when you want to also take ownership of all the subfolders and files in the specified folder. You can use the /d switch to specify the default answer the tool should use when it comes across subfolders for which you don't have List Folder permissions. In this case, the default answer is y (which stands for yes), meaning that the tool will allow you to take ownership of those subfolders, even though you don't have List Folder permissions.
To get a detailed overview of the Takeown command syntax, run the command: