Advertisement

Files are Locked Can’t Delete Use TakeOwn EXE and Delete the Files

The good news is TakeOwn.exe works with Windows 10 TP versions. TakeOwn.exe is the command line tool which can be used to take the ownership of files and folders. This tools works well with powershell as well command prompt. Now, you may think, why powershell? As part of PowerShell learning process, I’ve removed command prompt shortcuts from Windows 10 laptop. So by default for everything I use PowerShell rather than command prompt.

TakeOwn-EXE-6

TakeOwn-EXE-5

Following are the takeown.exe commands I tried from Powershell and command prompt.

PowerShell = PS C:\> takeown /f .\Windows.old /r /d y

Command prompt = C:\>takeown /f C:\Windows.old /r /d y

/R Recurse: instructs tool to operate on files in specified directory and all sub directories.

/F filename Specifies the filename or directory name pattern. Wildcard “*” can be used to specify the pattern. Allows sharename\filename.

/D prompt Default answer used when the current user does not have the “list folder” permission
on a directory. This occurs while operating recursively (/R) on sub-directories. Valid
values “Y” to take ownership or “N” to skip.

Take Ownership utility results are something similar to below screen shot. This TakeOwn utility can be used when you’re not able delete any of the files and folders even if you’ve full admin access on your Windows Machine. The random files getting locked and couldn’t be able delete is very common problem in Windows. In case, TakeOwn.exe doesn’t work for you, I would suggest to try PSEXEC with system account/machine account privileges to delete a file or folder from Windows 10 machine. I’ve explained this process  here “How to Run Application or Process from SYSTEM Context or Account“.

SUCCESS: The file (or folder): "C:\Windows.old\WINDOWS\winsxs\x86_wwf-system.workflow.activities_31bf3856ad364e35_6.1.7601.17514_none_346d5ccdd640c664\System.Workflow.Activities.d
ll" now owned by user "ACN\Anoop".
SUCCESS: The file (or folder): "C:\Windows.old\WINDOWS\winsxs\x86_wwf-system.workflow.componentmodel_31bf3856ad364e35_6.1.7601.17514_none_8deb83646c57c1d5\System.Workflow.Componen
tModel.dll" now owned by user "ACN\Anoop".

SUCCESS: The file (or folder): “C:\Windows.old\WINDOWS\winsxs\x86_wwf-system.workflow.runtime_31bf3856ad364e35_6.1.7601.17514_none_67224784fe4912e9\System.Workflow.Runtime.dll” no w owned by user “ACN\Anoop”.

TakeOwn-EXE-4

More help on Take Ownership tool !

Takeown C:/Windows.old\*

PS C:\WINDOWS\system32> Takeown /?

TAKEOWN [/S system [/U username [/P [password]]]]
/F filename [/A] [/R [/D prompt]]

Description:
This tool allows an administrator to recover access to a file that was denied by re-assigning file ownership.

Parameter List:
/S system Specifies the remote system to connect to.

/U [domain\]user Specifies the user context under which the command should execute.

/P [password] Specifies the password for the given user context. Prompts for input if omitted.

/F filename Specifies the filename or directory name pattern. Wildcard “*” can be used to specify the pattern. Allows sharename\filename.

/A Gives ownership to the administrators group instead of the current user.

/R Recurse: instructs tool to operate on files in specified directory and all sub directories.

/D prompt Default answer used when the current user does not have the “list folder” permission
on a directory. This occurs while operating recursively (/R) on sub-directories. Valid
values “Y” to take ownership or “N” to skip.

/SKIPSL Do not follow symbolic links. Only applicable with /R.

/? Displays this help message.

NOTE: 1) If /A is not specified, file ownership will be given to the
current logged on user.

2) Mixed patterns using “?” and “*” are not supported.

3) /D is used to suppress the confirmation prompt.

Examples:
TAKEOWN /?
TAKEOWN /F lostfile
TAKEOWN /F \\system\share\lostfile /A
TAKEOWN /F directory /R /D N
TAKEOWN /F directory /R /A
TAKEOWN /F *
TAKEOWN /F C:\Windows\System32\acme.exe
TAKEOWN /F %windir%\*.txt
TAKEOWN /S system /F MyShare\Acme*.doc
TAKEOWN /S system /U user /F MyShare\MyBinary.dll
TAKEOWN /S system /U domain\user /P password /F share\filename
TAKEOWN /S system /U user /P password /F Doc\Report.doc /A
TAKEOWN /S system /U user /P password /F Myshare\*
TAKEOWN /S system /U user /P password /F Home\Logon /R
TAKEOWN /S system /U user /P password /F Myshare\directory /R /A

About Author 

Anoop is Microsoft MVP and Veeam Vanguard ! He is a Solution Architect on enterprise client management with more than 13 years of experience (calculation done on the year 2014) in IT. He is Blogger, Speaker and Local User Group Community leader. His main focus is on Device Management technologies like SCCM 2012,Current Branch, Intune. He writes about the technologies like SCCM, SCOM, Windows 10, Azure AD, Microsoft Intune, RMS, Hyper-V etc...

    Find more about me on:
  • googleplus
  • twitter
  • facebook
  • linkedin
  • youtube
Posted in: Windows 10

Leave a Comment and Contact Anoop